I am writing ASP.NET project in C#.
The UpdateUserInfo.aspx page consists textboxes and button. In pageLoad() method I set some text to the textbox and when button is cicked I get the new value of textbox and write it into DB.
The problem is even if I have changed the value of textbox textbox.Text() method returns the old value of textbox ("sometext") and write this into DB.
Here the methods:
protected void Page_Load(object sender, EventArgs e)
{
textbox.text = "sometext";
}
void Btn_Click(Object sender,EventArgs e)
{
String textbox_text = textbox.text();// this is still equals "somevalue", even I change the textbox value
writeToDB(textbox_text);
}
So, how to make textbox to appear with somevalue initially, but when user changes this value getText method return the new changed value and write this into DB?
Postback is setting the textboxs text property back to
"somevalue"
on button click, you'll want to set the value only once as above.Postback explained:
Source
Reading up on View State will also be helpful in understanding how it all fits together.
Please check Page PostBack in the Page Load Event....
Try this:
Actually on page load
textbox
is re-initilized