SaveViewState called before events are fired

Discussion in 'ASP .Net' started by Louis Somers, Aug 8, 2008.

  1. Louis Somers

    Louis Somers Guest

    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
     
    Louis Somers, Aug 8, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper
    Replies:
    0
    Views:
    4,416
    Showjumper
    Jun 26, 2003
  2. David Palfery

    saveviewstate for the entire page

    David Palfery, May 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    440
    David Palfery
    May 2, 2004
  3. tshad

    SaveViewState executing twice

    tshad, Aug 25, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    819
    tshad
    Aug 30, 2006
  4. Stephen Miller

    Why is SaveViewState called twice in the Control Life Cycle?

    Stephen Miller, Dec 31, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    515
    Teemu Keiski
    Jan 1, 2004
  5. Teemu Keiski

    How to "track" a (child) control's ViewState / SaveViewState?

    Teemu Keiski, Apr 5, 2005, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    218
    Zarko Gajic
    Apr 6, 2005
Loading...

Share This Page