Mert Karatas
Mert Karatas

Reputation: 195

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.

Upvotes: 5

Views: 6910

Answers (2)

Tony Ashworth
Tony Ashworth

Reputation: 485

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

Upvotes: 0

DOK
DOK

Reputation: 32841

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
}

Upvotes: 13

Related Questions