简体   繁体   中英

Update a textbox in c#

In my function I recover a course from a sql database and display its features on a textbox. The idea of this is to then modify it and update the database, but it is like the textbox never changed and always takes the same value as in the Page_load. Here you have the page_load

Titulo.Text = curso.Title;
Description.Text = curso.Description;

And then on the On_click function I try to get the new values from the textbox (after modifying it) but I get the same ones I assigned before. Here is the code

curso.Title = Titulo.Text;
curso.Description = Description.Text;

Thanks everyone!

In your Page.Load event, you need to check if the page is being loaded for the first time, or from a postback (a button click or some other event), or else the values will be re-set to the initial values every time the page is loaded.

// set values on first load only
if (!Page.IsPostBack)
{
  Titulo.Text = curso.Title;
  Description.Text = curso.Description;
}

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