Textbox Question

  • Thread starter Thread starter Nick
  • Start date Start date
N

Nick

I've got a page with a bunch of textboxes that are populated from a db.
When I click a button it's supposed to read the values of the textboxes and
run a stored procedure - but it isn't quite working.

The button runs the sp, but doesn't use the current text in the textbox - it
uses the text that was loaded when the box was populated, and then ignores
the edited text. I think the form must be reloading the db content before
the button code runs - but where should I look?

Thanks
 
Nick said:
I've got a page with a bunch of textboxes that are populated from a db.
When I click a button it's supposed to read the values of the textboxes and
run a stored procedure - but it isn't quite working.

The button runs the sp, but doesn't use the current text in the textbox - it
uses the text that was loaded when the box was populated, and then ignores
the edited text. I think the form must be reloading the db content before
the button code runs - but where should I look?

Thanks

Guard the code that is populating the textbox (in your
Page_Load, I guess?) with a test for IsPostback.
Don't change the values if you are in a postback situation,
ASP.Net will fill in the user-values.

Remember: Page_Load is executed before "onclick" handlers.
 
check to see that you're not accidentally re-populating the text boxed on
the postback (probably in your page_load)
 
I'm checking to see if the textboxes are populated, before I (re)populate
them. It's working for most of the textboxes, but not for some of the
others!!!!????
 
The most common behavior would be to populate the textboxes only when the
page is first loaded, but never on a postback. ViewState will preserve the
values across postbacks sutomaticlaly.

Then when the user has made their adjustments and clicks your "Save" button,
you read the values and write them to the db.

Your Page_Load should contain;

if (!IsPostPack)
{
// load data into the text boxes
}
 
Back
Top