problem with textbox
On this code
After loading, the initial value for "empl" is "test"
<script language="VB" runat="server">
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
empl.Text = "test"
Sub display(ByVal sender As Object, ByVal e As EventArgs)
<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" />
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?
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.
Hope that helps.
If Not Page.IsPostBack Then
emp1.Text = "Test"
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)