Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Get Updated Value From Textbox

I have just began to develop web applications at visual studio, with c# and asp.net. In one of my pages, I have set the textbox's text value to something. The user can change the text and save it. Clicking save button, i got to get the new text value from the textbox but i always get the first text set. I would be so glad if you help me.

like image 499
Mert Karatas Avatar asked Feb 01 '12 13:02

Mert Karatas


1 Answers

Often this can be caused by setting the textbox value in Page_Load without wrapping that in !IsPostBack. When a page is submitted, the Page_Load event runs before the button click event. So, the textbox value gets repopulated with its original value before the click event looks at that value.

If this is the situation, then you can wrap the code that assigns the value to the textbox in an if block like this:

if (!IsPostBack)
{
   // set the textbox value
}
like image 93
DOK Avatar answered Oct 19 '22 21:10

DOK