Reputation: 2213
I am working on designing a user profile web page in asp.net using c#.
I first load the values of text boxes from database and put them in the text box:
txt_Name.Text = "somestring";
The user can then change the text in the text box to modify their profile.
However when I read txt_Name.Text
it shows me the "original" value instead of what the user entered.
More clearly:
txt_Name.Text = "somestring";
Response.Write(txt_Name.Text);
In 3 the value is the one from 1 instead of the one from 2
Upvotes: 2
Views: 3312
Reputation: 371
Its all in the page life cycle have a look at this page
http://msdn.microsoft.com/en-us/library/ms178472.aspx
Upvotes: 1
Reputation: 34369
It sounds like you aren't checking the Page.IsPostBack property (http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback.aspx) when you are setting the initial textbox value, so it is always being set no matter how the page is invoked.
private void Page_Load()
{
if (!IsPostBack)
{
txt_Name.Text = "somestring";
}
}
Upvotes: 5