0

Hello,

I haven't found a solution to this problem but I think it has to be something very simple.

I have an asp:Textbox in my page that fills with text from a database on page_load,
this works fine, the thing is that if I change the text and click in an asp:button that should retrieve the updated text, the code in the click event keeps getting the same value as if the textbox had the same text from the database and nothing had happen to it.

Why am I getting the same value?

Thanks in advance.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by MrCapuchino
0

On page postback the page is retaining the initially loaded value because the database code is being called again.
You will want your database code to be called inside this structure:

if(!Page.IsPostBack) {
  // call code to populate from database
}

Now that code only runs when the page is first loaded and not on postbacks (which happen when you click a button). The new value entered into textbox should now persist.
Hope that helps,

Edited by happygeek: fixed formatting

0

Hi,

Thanks, yes that was the problem, it makes sense, I was overwriting the textbox everytime I did a postback.

Thanks for your help

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.