Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > SaveViewState called before events are fired

Thread Tools

SaveViewState called before events are fired

Louis Somers
Posts: n/a

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) {
string PostBackRef = Page.ClientScript.GetPostBackEventReference(this, Item.Identificatie);
Attributes.Add("onclick", PostBackRef);

public event MyEvent OnClicked;

public void RaisePostBackEvent(string eventArgument) {
if (OnClicked != null) {

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)
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,
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedded <divs> with events: How to prevent the parent div's eventfrom being fired when the embedded div's event is fired? Num GG Javascript 2 11-17-2008 08:56 PM
Object reference not set to an instance of an object. System.Web.UI.WebControls.ListItemCollection.SaveViewState() System.Web.UI.WebControls.ListControl.SaveViewState() Brano ASP .Net 3 11-08-2005 12:29 PM
saveviewstate for the entire page David Palfery ASP .Net 2 05-02-2004 04:48 PM
Why is SaveViewState called twice in the Control Life Cycle? Stephen Miller ASP .Net Building Controls 1 01-01-2004 11:12 AM
Help w/ LoadViewState and SaveViewState subs Showjumper ASP .Net 0 06-26-2003 01:38 PM