A
Anand Sagar
I have a Panel1 and button1 on my webform. At runtime, I create 2 textboxes.
I do it at the Page_Load event. I put the code within the " If Not
isPostBack"
For the button click event, I will do a post-to-database coding and then
show the same page again. I put EnableViewState = True for the textboxes.
In the Page_Load if I dont use the IsPostBack checking, the code works fine.
The button shows that the code has been fired and the page is shown after
the network round trip with the values in the textboxes as it is.
If I put the IsPostBack checking, after the button click , the page shows
up with a empty Panel1 and a button.
What I want to know is, Shouldnt I be using the isPostBack checking ?
because otherwise the page will be recreating the textboxes everytime when
the button is clicked ?
What are the issues about the IsPostBack checking when controls are creating
at runtime. Please give ideas.
Here is the code.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Put user code to initialize the page here
Dim t1 As New TextBox()
Dim t2 As New TextBox()
t1.Text = "sagar"
t1.ID = "t1"
t1.EnableViewState = True
'AddHandler t1.TextChanged, AddressOf DoThis
Panel1.Controls.Add(t1)
t2.Text = "Tres"
t2.ID = "t2"
t2.EnableViewState = True
Panel1.Controls.Add(t2)
End If
End Sub
Sub DoThis(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("feeling great")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim c As Control
Dim t As TextBox
For Each c In Panel1.Controls
If c.GetType.ToString = "System.Web.UI.WebControls.TextBox" Then
Response.Write("-------")
Response.Write("ClientID = " & c.ClientID)
Response.Write("ID = " & c.ID)
Response.Write("Unique ID = " & c.UniqueID)
Response.Write("GetType = " & c.GetType.ToString)
t = CType(c, TextBox)
Response.Write("text = " & t.Text)
Response.Write("<p>")
End If
Next
End Sub
Thanks,
Anand Sagar.
I do it at the Page_Load event. I put the code within the " If Not
isPostBack"
For the button click event, I will do a post-to-database coding and then
show the same page again. I put EnableViewState = True for the textboxes.
In the Page_Load if I dont use the IsPostBack checking, the code works fine.
The button shows that the code has been fired and the page is shown after
the network round trip with the values in the textboxes as it is.
If I put the IsPostBack checking, after the button click , the page shows
up with a empty Panel1 and a button.
What I want to know is, Shouldnt I be using the isPostBack checking ?
because otherwise the page will be recreating the textboxes everytime when
the button is clicked ?
What are the issues about the IsPostBack checking when controls are creating
at runtime. Please give ideas.
Here is the code.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Put user code to initialize the page here
Dim t1 As New TextBox()
Dim t2 As New TextBox()
t1.Text = "sagar"
t1.ID = "t1"
t1.EnableViewState = True
'AddHandler t1.TextChanged, AddressOf DoThis
Panel1.Controls.Add(t1)
t2.Text = "Tres"
t2.ID = "t2"
t2.EnableViewState = True
Panel1.Controls.Add(t2)
End If
End Sub
Sub DoThis(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("feeling great")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim c As Control
Dim t As TextBox
For Each c In Panel1.Controls
If c.GetType.ToString = "System.Web.UI.WebControls.TextBox" Then
Response.Write("-------")
Response.Write("ClientID = " & c.ClientID)
Response.Write("ID = " & c.ID)
Response.Write("Unique ID = " & c.UniqueID)
Response.Write("GetType = " & c.GetType.ToString)
t = CType(c, TextBox)
Response.Write("text = " & t.Text)
Response.Write("<p>")
End If
Next
End Sub
Thanks,
Anand Sagar.