postback and viewstate

C

crespo

Hi,everyone,
I have implemented a user control with a button that can show up a modal
dialog. After the modal dialog is closed, a postback event occur and my user
control can successfully receive the return value from the closed modal
dialog. I implemented IPostBackEventHandler for the user control.My problem
is, in the event handler i changed a variable's view state,but when I check
my codes in the user control's overrided Render() function,I found the
variable's view state has been restored to the previous value before I
changed. It sounds very odd,and i am sure i have not changed the variable
anywhere.
Could anyone hele me?

Crespo
 
C

crespo

Thanks for your concern. I only place partial codes below.

The statement of the variable which can be tracked in view state is :
public string time
{
get { return this.ViewState["__timeStamp"].ToString(); }

set { this.ViewState["__timeStamp"] = value; }
}

In the event handler that does with post back event is::

//do something to save a record of table
.........................
// get the timestamp and convert it to string
................................
// then save the value of timestamp
this.time = "xxxxxxxxxxx".//new time stamp after saving successfully

Actually I implement the IPostbackEventHandler for my own page class
inherited from System.web.ui.page. and the javascript for post back is
like:
__doPostBack("_page","");

As it did the trick, I don't think it is important to list those codes in
order to firgure out the problem. One of my doubt is: when
IPostbackEventHandler is implmented in my own page class,Is there a
difference
from those case in which IPostbackEventHandler is implemented in other
server controls. Another question is : As processing post back event always
happens behind loading view state,why is the variable "time" gonna be
restored to previous value ?

Hope these simple code can help you to solve out my question. Thanks.

Crespo
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top