SaveViewState called before events are fired

L

Louis Somers

Hi,

I have a simple ASPX page called Default.aspx. On it (nested within allot of other stuff) I have a
custom control which inherits from TableRow and implements IPostBackEventHandler.

This custom control hast the following code:

---------
protected override void OnInit(EventArgs e) {
base.OnInit(e);
string PostBackRef = Page.ClientScript.GetPostBackEventReference(this, Item.Identificatie);
Attributes.Add("onclick", PostBackRef);
}

public event MyEvent OnClicked;

public void RaisePostBackEvent(string eventArgument) {
if (OnClicked != null) {
OnClicked(this);
return;
}
}
----------

At first this seemed to work fine. The event is triggered correctly when the user clicks the table
row. However, in the eventhandler I create allot of new controls which are dynamically added to the
page. These are rendered correctly but are for some reason not persistent.

To figure out why, I override some methods in the default.aspx page and plot out the entire control
tree to the trace. I did this on:
LoadViewState(object savedState)
OnPreRender(EventArgs e)
SaveViewState()
and also in the event handler of my custom TableRow.

To my astonishment I found that SaveViewState is being called before the event is triggered!
Can someone please explain what I am doing wrong and why?

Thanks in advance,
Louis
 

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,754
Messages
2,569,529
Members
45,001
Latest member
Kendra00E1

Latest Threads

Top