Do you receive the Programmer's Heaven newsletter? If not, why not subscribe?

VB.NET

Moderators: seancampbell
Number of threads: 3618
Number of posts: 9200

This Forum Only
Post New Thread

Report
Help::Automatic textbox generation Posted by thushara on 12 Nov 2009 at 8:26 AM
Sub textbox1_textchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim count As Integer
Dim t As New TextBox
For count = 4 To 6
MsgBox("vbbvbnv")
t.Text = "TextBox" & count.ToString()
t.ID = "TextBox" & count.ToString()
Panel1.Controls.Add(t)
count = count + 1

Next count

end sub

ERROR::::Multiple controls with the same ID 'TextBox6' were found. FindControl requires that controls have unique IDs.
Description: An unhandled exception occurred during the execution of the current web request.How Can i Rectify this
Report
Re: Help::Automatic textbox generation Posted by A_Bit_T13d_Up on 12 Nov 2009 at 11:28 AM
Hi,

Move the line of code.>>

Dim t As New TextBox to just after.>>

For count As Integer = 4 to 6

that way you generate a NEW textbox each time.

Give each a Location too. Try

t.Location = New Point(count * 75,50)

within the loop too.

If this is a Web based project you could also try.>>

http://forums.asp.net/


Best of luck and Happy coding.
Report
Re: Help::Automatic textbox generation Posted by A_Bit_T13d_Up on 12 Nov 2009 at 11:30 AM
Hi,

I would do this with a button click though, not within a TextChanged event otherwise you will generate New TextBoxes every time the text is changed.

As this looks like a WINDOWS FORM based project you would need.>>

t.Name = "TextBox" & count.ToString

within the FOR NEXT next loop instead of

t.Id = "TextBox" & count.ToString

Remove the line

count = count + 1

as it interferes wih the FOR NEXT loop.

How many TextBoxes are you wanting in the end?

Best of luck and Happy coding.



 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A bootstrapLabs project.