Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with textbox/postback

Status
Not open for further replies.

phbrady

Programmer
Oct 17, 2003
41
US
Hi,

I have an issue that would appear to be a bug in .Net, but maybe it's something I'm doing. In Page_Load, I am creating a textbox dynamically, and then setting its "Text" property to a particular value. After a postback, the textbox does not contain the value I have assigned to it, even though I can do a response.write(TextBox.Text) and the value I assigned is written to the page! I know that textboxes are supposed to retain their value on postback, so maybe this has to do with exactly when I am setting the "Text" property of the textbox.

Hope this makes sense...
 
You need to create all objects each time you walk in the page wich means you have to create them in Page_load or in any method caled from that page but outside of the IsPostback() function

Something like this
Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load      
        If Not IsPostBack() Then
           'do the first inits thing (for examlpe initialize session, etc)
        End If
        'create controls here or call an external function wich creates all the controls for example
    End Sub
 
I am creating the objects in Page_Load and outside of the IsPostBack() function.
I think I am going to approach this a different way, but I'd still like to know why this is happening.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top