georgepatotk Posted April 19, 2004 Posted April 19, 2004 Sub ShowMyTextBox() Dim MyTextBox As New TextBox MyTextBox.ID = "MyTextBox" MyTextBox.Text = "MyTextBox" Me.Panel1.Controls.Add(MyTextBox) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ShowMyTextBox() End Sub As pasted above, I have two button in a web form. Button1 is to create a textbox. I have the other button named Button2. When I press Button2, the created text box is disappear. Can you tell me why the created textbox is disappear when I press button2?? Quote George C.K. Low
wessamzeidan Posted April 19, 2004 Posted April 19, 2004 Dynamically created controls should be recreated on every postback.... Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
georgepatotk Posted April 19, 2004 Author Posted April 19, 2004 in my case, how to recreate it?? Please tell me some hints. thanks.. Quote George C.K. Low
wessamzeidan Posted April 19, 2004 Posted April 19, 2004 I'm not sure, but I think you just have to call ShowMyTextBox() again Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
georgepatotk Posted April 19, 2004 Author Posted April 19, 2004 YeH... thanks a lot.. I think I had figured out a way to do so.. First, I declare a global flag variable in my main aspx. When I create ShowMyTextBox(), I will set the flag to true. so, everytime I post back the page, I will read the global variable. If it is not false, I will call ShowMyTextBox() Quote George C.K. Low
wessamzeidan Posted April 19, 2004 Posted April 19, 2004 So it worked......good. But I have a question for you, when you recreate the control, are you able to read the values entered by the user in this textbox?? Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
georgepatotk Posted April 19, 2004 Author Posted April 19, 2004 ok, a way to make the value remained. Dim txt1 as new TextBox Private Sub Load(....) if txt1.text <> "" then me.controls.add(txt1) end if End Sub Private Sub Button1_Click(.....) Handles Button1.Click txt1.text = "Hello" me.controls.add(txt1) End Sub Got my idea??? Quote George C.K. Low
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.