|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi All,
I have some Problem Accessing dynamically created controls. Actually what I have to do is I have to get different set of questiond based on the order type. For example , OrderType A may have 5 questions . It can be a short text, Long Text or a multiple choice question and OrderType B may have 3 questions of different Type. I have to create different control(textbox, multi line textbox, radioButton) based on the que type. I am adding all the controls to a table and the table to a placeholder. I don't have any problem creating the questions and controls dynamically. But the problem bubble up when i try to access the dynamically created control. I am creating the control in the Page_Init and I am trying to get the response from those dynamically created control once the user click on the submit button. Here is the code: PrivateSub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Init Dim mytable AsNew Table Dim que As DataTable Dim qrow As DataRow Dim row AsInteger IfNot IsPostBack Then Dim myorderid = CInt(1) Dim myaccount As DNS.OrdersDB = New DNS.OrdersDB myserviceid = myaccount.GetServiceType(myorderid) que = New DataTable que = DNS.QADB.GetQuestions(myserviceid).Tables(0) row = CInt(que.Rows.Count) Dim i AsInteger For i = 0 To row - 1 qrow = que.Rows(i) Dim mytype AsString = qrow("QueType") Dim myreq AsString = qrow("QueRequired") If mytype = "SHORT TEXT" Then Dim myrow AsNew TableRow Dim myrow1 AsNew TableRow Dim mycell AsNew TableCell Dim mycell1 AsNew TableCell Dim lbl As Label = New Label lbl.Text = qrow("QueName") Dim mylblid AsString = "lbl" + CStr(qrow("Queid")) lbl.ID = mylblid Dim txt As TextBox = New TextBox txt.ID = qrow("Queid").ToString() txt.Width = Unit.Pixel(Convert.ToInt32(200).ToString()) mycell.Controls.Add(lbl) mycell1.Controls.Add(txt) myrow.Cells.Add(mycell) myrow1.Cells.Add(mycell1) mytable.Rows.Add(myrow) mytable.Rows.Add(myrow1) ElseIf (mytype = "LONG TEXT") Then ' as added above End If Next myplace.Controls.Add(mytable) EndIf EndSub Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click Dim mytable As New Table Dim que As DataTable Dim qrow As DataRow Dim row As Integer Dim myorderid = CInt(1) Dim myaccount As DNS.OrdersDB = New DNS.OrdersDB myserviceid = myaccount.GetServiceType(myorderid) que = New DataTable que = DNS.QADB.GetQuestions(myserviceid).Tables(0) row = CInt(que.Rows.Count) Dim i As Integer For i = 0 To row - 1 qrow = que.Rows(i) Dim mytype As String = qrow("QueType") Dim myreq As String = qrow("QueRequired") If mytype = "SHORT TEXT" Or mytype = "LONG TEXT" Then ' Trying to get the value of the textbox Dim c As TextBox = Page.FindControl(qrow("QueId")) Dim myresponse As String = c.Text If myreq = "YES" And myresponse = "" Then lblerr.Text = qrow("QueName") lblerr.Visible = True Else Dim mysystem As DNS.QADB = New DNS.QADB Dim mystsring As String = mysystem.addQAResponse(qrow("QueId"), myresponse) End If End If Next End Sub It's really very urgent. Please someone help me with this. Any Help is greatly appreciated Thanks |
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > Problem Accessing Dynamically Created Control |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|