简体   繁体   中英

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.

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
}

The problem is probably that your text box isn't properly tied to your view model. Some sample code could help verify though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM