T
T-Bone
Hi there,
I read a lot about this issue but still got no clear answer that
solves my problem.
I've a Web User Control with a placeholder called phProperties.
I create a form with a number of Textboxes dynamically from values in
a database and add them to the phProperties placeholder. The number of
Textboxes depends on the template the user clicked. Each template has
his own number of properties.
I store the controlnames in a hashtable called 'templatepropertynames'
After the user clicks a button, I want to store the values from the
textboxes in a database.
The problem is that I can't get to the controls in the Button_click
event.
I tried with FindControl but with no result.
When debugging the value of myEnumerator.value in the button_click
event is correct which is the name of the control but:
The 'value' of
phProperties.FindControl(myEnumerator.value) is always 'nothing'
in the button_click event where I expected a reference to the
textbox.
How can I retreive the values from the Textboxes in the Button_click
event.
Here my code:
Private Sub CreatePropertyFields(ByVal templateid As Integer)
Dim getproperties As New SqlCommand("select * from
TemplateProperties where templateID=" & templateid, myConnection)
Dim propertyreader As SqlDataReader
myConnection.Open()
propertyreader = getproperties.ExecuteReader
Dim templatepropertynames As New Hashtable
While propertyreader.Read
templatepropertynames(propertyreader.Item("propertyID")) =
propertyreader.Item("propertyName")
'create label for textbox
Dim propertylbl As New Label
propertylbl.Text =
propertyreader.Item("propertyName").trim
propertylbl.Width = Unit.Pixel(200)
Me.phProperties.Controls.Add(propertylbl)
'create the Textbox
Dim newcontrol As New TextBox
newcontrol.ID =
propertyreader.Item("propertyName").trim
Me.phProperties.Controls.Add(newcontrol)
'create seperator
Dim seperatorlbl As New Label
seperatorlbl.Text = "<br>"
Me.phProperties.Controls.Add(seperatorlbl)
End While
Session("propertynames") = templatepropertynames
myConnection.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNaar4.Click
Dim templatepropertynames As New Hashtable
templatepropertynames = Session("propertynames")
Dim myEnumerator As IDictionaryEnumerator =
templatepropertynames.GetEnumerator()
While myEnumerator.MoveNext()
Dim Textboxvalue As String =
CType(phProperties.FindControl(myEnumerator.value), Textbox).Text
'insert textboxvalue in the database here
End While
End Sub
Thanks in advance
Peter
I read a lot about this issue but still got no clear answer that
solves my problem.
I've a Web User Control with a placeholder called phProperties.
I create a form with a number of Textboxes dynamically from values in
a database and add them to the phProperties placeholder. The number of
Textboxes depends on the template the user clicked. Each template has
his own number of properties.
I store the controlnames in a hashtable called 'templatepropertynames'
After the user clicks a button, I want to store the values from the
textboxes in a database.
The problem is that I can't get to the controls in the Button_click
event.
I tried with FindControl but with no result.
When debugging the value of myEnumerator.value in the button_click
event is correct which is the name of the control but:
The 'value' of
phProperties.FindControl(myEnumerator.value) is always 'nothing'
in the button_click event where I expected a reference to the
textbox.
How can I retreive the values from the Textboxes in the Button_click
event.
Here my code:
Private Sub CreatePropertyFields(ByVal templateid As Integer)
Dim getproperties As New SqlCommand("select * from
TemplateProperties where templateID=" & templateid, myConnection)
Dim propertyreader As SqlDataReader
myConnection.Open()
propertyreader = getproperties.ExecuteReader
Dim templatepropertynames As New Hashtable
While propertyreader.Read
templatepropertynames(propertyreader.Item("propertyID")) =
propertyreader.Item("propertyName")
'create label for textbox
Dim propertylbl As New Label
propertylbl.Text =
propertyreader.Item("propertyName").trim
propertylbl.Width = Unit.Pixel(200)
Me.phProperties.Controls.Add(propertylbl)
'create the Textbox
Dim newcontrol As New TextBox
newcontrol.ID =
propertyreader.Item("propertyName").trim
Me.phProperties.Controls.Add(newcontrol)
'create seperator
Dim seperatorlbl As New Label
seperatorlbl.Text = "<br>"
Me.phProperties.Controls.Add(seperatorlbl)
End While
Session("propertynames") = templatepropertynames
myConnection.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNaar4.Click
Dim templatepropertynames As New Hashtable
templatepropertynames = Session("propertynames")
Dim myEnumerator As IDictionaryEnumerator =
templatepropertynames.GetEnumerator()
While myEnumerator.MoveNext()
Dim Textboxvalue As String =
CType(phProperties.FindControl(myEnumerator.value), Textbox).Text
'insert textboxvalue in the database here
End While
End Sub
Thanks in advance
Peter