Label retains old text...

P

ProgramAnalyst

Hey all,

I have a label that gets its text from a DB. This text can be changed
on the page in a textbox and after the save button is clicked the new
text is updated in the DB and the page refreshes.

The problem: Even though in the page_load method the label's text is
being set to what is in the DB the text is still the old text. If u
refresh the page the text then updates. Why is this happening? The
label's viewstate is false and if I create a method that does the
exact same thing as page load it works for some of the labels (this
is affect all labels that get updated) but not for others.

Any ideas?

Thanks.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
S

Steve C. Orr [MVP, MCSD]

The Save button's click event is called after Page_Load.

Therefore you are probably setting the label text from the database, then
updating the database. This is the wrong order for what you need and that's
why the page displays improperly.
Perhaps you should re-set the label text property in the save button's click
event.

Or you could move the code that sets the label text to the Page_PreRender or
Page_Render event, both of which are called after the button click event.

If you've got the time, I suggest you study the lifecycle of pages and
controls.
Here are some good articles on the subject:
http://www.15seconds.com/issue/020102.htm
http://msdn.microsoft.com/library/d...on/html/vbconWebFormsPageProcessingStages.asp
http://msdn.microsoft.com/library/d...guide/html/cpconcontrolexecutionlifecycle.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top