Results 1 to 2 of 2

Thread: problem with textbox

  1. #1
    Join Date
    Nov 2005

    problem with textbox


    On this code

    PHP Code:
    <script language="VB" runat="server">
    Sub Page_Load(ByVal Sender As ObjectByVal E As EventArgs)
    empl.Text "test"
    End Sub

        Sub display
    (ByVal sender As ObjectByVal e As EventArgs)
    End Sub

    <body onLoad="Page_Load" runat=server>
    <form id="form1" runat="server">
    <asp:TextBox id="empl" runat="server"/>
    <asp:Button id=Button1 Text="submit" runat="server" OnClick="display" />
    After loading, the initial value for "empl" is "test"
    But, when I type something else in the textbox and submit, how come the value is still test?
    How can I change the textbox value after typing?


  2. #2
    Join Date
    Jun 2004
    Kansas City, MO
    Your problem with this example is that even though your changing the text within the textbox, when the page posts back it's calling the page load first and then your displays sub causing the text in the textbox to be re-set to test.

    Here is a link that will show you the page life cycle. This will show you the order of the events:

    Any way to solve your problem you can add this to your page load. I personally use this code in basically ever page load sub because there is stuff that I want to happen when the page is visited for the first time but not on posts backs.

    This code will only fire when the page is first loaded. When you click the button and cause a post back this code will not be hit and thus when you write the value of the textbox youll get the new value that was entered.
    If Not Page.IsPostBack Then 
            emp1.Text = "Test"
    End If
    Hope that helps.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center