471,357 Members | 1,122 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 software developers and data experts.

Create controls dynamically: Getting an error

Hi all
Pls give me some insight as to what I should be doing.
I have a form where I have 20 text boxes and when an user submits the form I
save it to a database. When they want to retrieve it, I loop and create the
textboxes with ID and text value and then add to the form. The problem is
when trying to create the control in the code behind page I get the error
"Multiple controls with the same ID 'txtQLLink1' were found".
How do I retrieve the data and display it in the text boxes in the form?

Thanks
V
Jul 21 '05 #1
3 2214
Hi Varad,
"Multiple controls with the same ID 'txtQLLink1' were found". This means that you were not able to assign unique IDs to controls in your
page. Check whether the loop in which you are re-creating the controls, you
are also incrementing the index value for the control. This will ensure that
they get unique names like txtQLLink1, txtQLLink2, txtQLLink3 ...

If this is working fine, then you must be having some other textbox with the
same ID.

HTH,

Need any help, do post a msg back..
Happy Coding

"Varad" wrote:
Hi all
Pls give me some insight as to what I should be doing.
I have a form where I have 20 text boxes and when an user submits the form I
save it to a database. When they want to retrieve it, I loop and create the
textboxes with ID and text value and then add to the form. The problem is
when trying to create the control in the code behind page I get the error
"Multiple controls with the same ID 'txtQLLink1' were found".
How do I retrieve the data and display it in the text boxes in the form?

Thanks
V

Jul 21 '05 #2
Hi Vishnu
Thanks for responding. I have controls already named txtQlLink1, txtQLLink2
etc in the .aspx form. I created those controls by dragging and dropping them
on to the form first. Now, I'm trying to reload the page with values
retrieved from the database but doing it in a loop instead of having to do it
for each control.

This is the code that is used to set the code to the text conrols:
For Each arrValueQL As String In arrQC
qlCount = qlCount + 1
If arrValueQL <> "" Then
If (qlCount Mod 2) = 1 Then
Dim txtQLLink As New TextBox
txtQLLink.ID = "txtQLLink" & i.ToString
txtQLLink.Text = arrValueQL
Me.FindControl("Form1").Controls.Add(txtQLLink)
ElseIf (qlCount Mod 2) = 0 Then
Dim txtQLUrl As New TextBox
txtQLUrl.ID = "txtQLUrl" & i.ToString
txtQLUrl.Text = arrValueQL
Me.FindControl("Form1").Controls.Add(txtQLUrl)
i = i + 1
End If
End If
Next


"Vishnu-Chivukula" wrote:
Hi Varad,
"Multiple controls with the same ID 'txtQLLink1' were found".

This means that you were not able to assign unique IDs to controls in your
page. Check whether the loop in which you are re-creating the controls, you
are also incrementing the index value for the control. This will ensure that
they get unique names like txtQLLink1, txtQLLink2, txtQLLink3 ...

If this is working fine, then you must be having some other textbox with the
same ID.

HTH,

Need any help, do post a msg back..
Happy Coding

"Varad" wrote:
Hi all
Pls give me some insight as to what I should be doing.
I have a form where I have 20 text boxes and when an user submits the form I
save it to a database. When they want to retrieve it, I loop and create the
textboxes with ID and text value and then add to the form. The problem is
when trying to create the control in the code behind page I get the error
"Multiple controls with the same ID 'txtQLLink1' were found".
How do I retrieve the data and display it in the text boxes in the form?

Thanks
V

Jul 21 '05 #3
Hi varad!

I have not played with Vb or web development on a .net language yet... but
as far as I can see you allready have a textbox with that id.... I notice
that you are declaring new textboxes where you already have those textboxes
ids in your form. In a regular application you could access the form's
Controls property and itenerate over the allready created control... find
the controls that are textboxes and have the specific id... and just change
their properties, instead of re-declaring a whole new textbox.
I am out of my environment since i code under c# and applications... but I
just thought I would give my two cents.
"Varad" <Va***@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
Hi Vishnu
Thanks for responding. I have controls already named txtQlLink1,
txtQLLink2
etc in the .aspx form. I created those controls by dragging and dropping
them
on to the form first. Now, I'm trying to reload the page with values
retrieved from the database but doing it in a loop instead of having to do
it
for each control.

This is the code that is used to set the code to the text conrols:
For Each arrValueQL As String In arrQC
qlCount = qlCount + 1
If arrValueQL <> "" Then
If (qlCount Mod 2) = 1 Then
Dim txtQLLink As New TextBox
txtQLLink.ID = "txtQLLink" & i.ToString
txtQLLink.Text = arrValueQL
Me.FindControl("Form1").Controls.Add(txtQLLink)
ElseIf (qlCount Mod 2) = 0 Then
Dim txtQLUrl As New TextBox
txtQLUrl.ID = "txtQLUrl" & i.ToString
txtQLUrl.Text = arrValueQL
Me.FindControl("Form1").Controls.Add(txtQLUrl)
i = i + 1
End If
End If
Next


"Vishnu-Chivukula" wrote:
Hi Varad,
> "Multiple controls with the same ID 'txtQLLink1' were found".

This means that you were not able to assign unique IDs to controls in
your
page. Check whether the loop in which you are re-creating the controls,
you
are also incrementing the index value for the control. This will ensure
that
they get unique names like txtQLLink1, txtQLLink2, txtQLLink3 ...

If this is working fine, then you must be having some other textbox with
the
same ID.

HTH,

Need any help, do post a msg back..
Happy Coding

"Varad" wrote:
> Hi all
> Pls give me some insight as to what I should be doing.
> I have a form where I have 20 text boxes and when an user submits the
> form I
> save it to a database. When they want to retrieve it, I loop and create
> the
> textboxes with ID and text value and then add to the form. The problem
> is
> when trying to create the control in the code behind page I get the
> error
> "Multiple controls with the same ID 'txtQLLink1' were found".
> How do I retrieve the data and display it in the text boxes in the
> form?
>
> Thanks
> V

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Patrick Marti | last post: by
reply views Thread by Johnny Fugazzi | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.