Ask a Question related to ASP.NET Building Controls, Design and Development.
-
T-Bone #1
Access dynamically created controls
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("propert yID")) =
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
T-Bone Guest
-
Eventhandling from dynamically created controls
I have some questions reguarding event handling of dynamically added controls. An example scenario (se code below): I have one button declared... -
Dynamically created user controls
In ASP.Net, I am working with some in-house software that dynamically creates a form based on rows in a database table. For example, most pages... -
Referencing Dynamically created controls
Can anyone tell me how to reference a a control, e.g. a control I have added to the controls collection without specifically naming it. Also can... -
retrieving values from dynamically created controls
Hi, Someone please clear this for me! I display a bunch of button controls on a page dynamically, adding them to a placeholder control in my... -
get formvalues - dynamically created controls
C.H., You could loop through them using their index. Instead of using FindControl and the control's name you could just use the index of the... -
John Saunders #2
Re: Access dynamically created controls
"T-Bone" <sub@pox.nl> wrote in message
news:4378c773.0407020120.49a9b8c0@posting.google.c om...Dynamically added controls need to be added on every request, and in the> 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.
exact same order.
--
John Saunders
johnwsaundersiii at hotmail
John Saunders Guest
-
T-Bone #3
Re: Access dynamically created controls
"John Saunders" <johnwsaundersiii@notcoldmail.com> wrote in message news:<emsDZRFYEHA.712@TK2MSFTNGP11.phx.gbl>...
> "T-Bone" <sub@pox.nl> wrote in message
> news:4378c773.0407020120.49a9b8c0@posting.google.c om...>> > 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.
> Dynamically added controls need to be added on every request, and in the
> exact same order.
OK, but what about the values. If I create the controls on every page
request the values will be empty every time the page is loaded and I
never can get to the submitted values. or not?
T-Bone Guest
-
P K #4
Re: Access dynamically created controls
Ok, but what about the values. If I create the values on every page
request, the entered values in the Textboxes before the button click
will be gone. Or not?
*** Sent via Devdex [url]http://www.devdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
P K Guest
-
T-Bone #5
Re: Access dynamically created controls
"John Saunders" <johnwsaundersiii@notcoldmail.com> wrote in message news:<emsDZRFYEHA.712@TK2MSFTNGP11.phx.gbl>...
Ok, but what about the values in the Textbox. If I create the controls> "T-Bone" <sub@pox.nl> wrote in message
> news:4378c773.0407020120.49a9b8c0@posting.google.c om...>> > 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.
> Dynamically added controls need to be added on every request, and in the
> exact same order.
on every page_load the values will be empty every time. How can I get
to the submitted values?
T-Bone Guest
-
John Saunders #6
Re: Access dynamically created controls
"T-Bone" <sub@pox.nl> wrote in message
news:4378c773.0407042304.289ab5bf@posting.google.c om...news:<emsDZRFYEHA.712@TK2MSFTNGP11.phx.gbl>...> "John Saunders" <johnwsaundersiii@notcoldmail.com> wrote in messageViewState will take care of that for you.>> > "T-Bone" <sub@pox.nl> wrote in message
> > news:4378c773.0407020120.49a9b8c0@posting.google.c om...> >> > > 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.
> > Dynamically added controls need to be added on every request, and in the
> > exact same order.
> Ok, but what about the values in the Textbox. If I create the controls
> on every page_load the values will be empty every time. How can I get
> to the submitted values?
--
John Saunders
johnwsaundersiii at hotmail
John Saunders Guest



Reply With Quote

