how to fire custom server control events before Page_Load event

Discussion in 'ASP .Net' started by Michal Valent, Dec 4, 2007.

  1. I would like to fire some custom server control event before Page_Load event
    like this (from the trace of an aspx page) :

    Trace Information
    Category Message From First(s) From Last(s)
    aspx.page Begin PreInit
    aspx.page End PreInit 5,38454603734274E-05 0,000054
    aspx.page Begin Init 8,96405962016187E-05 0,000036
    aspx.page End Init 0,00072941040948794 0,000640
    aspx.page Begin InitComplete 0,000772971258380746 0,000044
    aspx.page End InitComplete 0,000803692870689425 0,000031
    aspx.page Begin LoadState 0,000834735021502791 0,000031
    aspx.page End LoadState 0,00178558244517456 0,000951

    aspx.page Begin ProcessPostData 0,00183099373614339 0,000045
    customPaging.aspx Grid_PageIndexChanged 0,0109000220370222 0,009069 --- THE
    CUSTOM SERVER CONTROL EVENT FIRED HERE
    aspx.page End ProcessPostData 0,0742993505756337 0,063399

    aspx.page Begin PreLoad 0,0743912900339237 0,000092
    aspx.page End PreLoad 0,0744449925875471 0,000054
    aspx.page Begin Load 0,0744761125357267 0,000031
    customPaging.aspx Page_Load 0,0745075526885167 0,000031 --- THE PAGE LOAD
    EVENT FIRED HERE
    aspx.page End Load 0,0746396646365895 0,000132
    aspx.page Begin ProcessPostData Second Try 0,0746623954910917 0,000023
    aspx.page End ProcessPostData Second Try 0,0746837463605524 0,000021
    aspx.page Begin Raise ChangedEvents 0,0747043760183775 0,000021
    aspx.page End Raise ChangedEvents 0,0747389591179849 0,000035
    aspx.page Begin Raise PostBackEvent 0,0747599143227289 0,000021
    aspx.page End Raise PostBackEvent 0,0747898419344499 0,000030



    According to the aspx page lifecycle - the custom server control events
    could be fired in the

    aspx.page Begin Raise PostBackEvent 0.099569 0.000043
    aspx.page End Raise PostBackEvent 0.489606 0.360924

    PostBackEvent section.



    thanks
    mike
    Michal Valent, Dec 4, 2007
    #1
    1. Advertising

  2. you keep asking this, but never say what you are trying to do, making it hard
    for anyone to give a better answer than sure you can.

    here is a custom textbox control that the TextChanged event before onload
    (as soon as postback data is availiable).

    public class MyTextBox : TextBox
    {
    protected override bool LoadPostData(
    string postDataKey,
    System.Collections.Specialized.NameValueCollection
    postCollection)
    {
    bool returnValue = base.LoadPostData(postDataKey, postCollection);
    base.RaisePostDataChangedEvent();
    return returnValue;
    }
    protected override void RaisePostDataChangedEvent(){}
    }

    -- bruce (sqlwork.com)


    "Michal Valent" wrote:

    > I would like to fire some custom server control event before Page_Load event
    > like this (from the trace of an aspx page) :
    >
    > Trace Information
    > Category Message From First(s) From Last(s)
    > aspx.page Begin PreInit
    > aspx.page End PreInit 5,38454603734274E-05 0,000054
    > aspx.page Begin Init 8,96405962016187E-05 0,000036
    > aspx.page End Init 0,00072941040948794 0,000640
    > aspx.page Begin InitComplete 0,000772971258380746 0,000044
    > aspx.page End InitComplete 0,000803692870689425 0,000031
    > aspx.page Begin LoadState 0,000834735021502791 0,000031
    > aspx.page End LoadState 0,00178558244517456 0,000951
    >
    > aspx.page Begin ProcessPostData 0,00183099373614339 0,000045
    > customPaging.aspx Grid_PageIndexChanged 0,0109000220370222 0,009069 --- THE
    > CUSTOM SERVER CONTROL EVENT FIRED HERE
    > aspx.page End ProcessPostData 0,0742993505756337 0,063399
    >
    > aspx.page Begin PreLoad 0,0743912900339237 0,000092
    > aspx.page End PreLoad 0,0744449925875471 0,000054
    > aspx.page Begin Load 0,0744761125357267 0,000031
    > customPaging.aspx Page_Load 0,0745075526885167 0,000031 --- THE PAGE LOAD
    > EVENT FIRED HERE
    > aspx.page End Load 0,0746396646365895 0,000132
    > aspx.page Begin ProcessPostData Second Try 0,0746623954910917 0,000023
    > aspx.page End ProcessPostData Second Try 0,0746837463605524 0,000021
    > aspx.page Begin Raise ChangedEvents 0,0747043760183775 0,000021
    > aspx.page End Raise ChangedEvents 0,0747389591179849 0,000035
    > aspx.page Begin Raise PostBackEvent 0,0747599143227289 0,000021
    > aspx.page End Raise PostBackEvent 0,0747898419344499 0,000030
    >
    >
    >
    > According to the aspx page lifecycle - the custom server control events
    > could be fired in the
    >
    > aspx.page Begin Raise PostBackEvent 0.099569 0.000043
    > aspx.page End Raise PostBackEvent 0.489606 0.360924
    >
    > PostBackEvent section.
    >
    >
    >
    > thanks
    > mike
    >
    >
    >
    bruce barker (sqlwork.com), Dec 4, 2007
    #2
    1. Advertising

  3. Thank you very much, bruce.

    I was keep making the code like :

    public class MyTextBox: Control, IPostBackDataHandler
    {
    public String Text {
    get {
    return (String) ViewState["Text"];
    }

    set {
    ViewState["Text"] = value;
    }
    }

    public event EventHandler TextChanged;

    public virtual bool LoadPostData(string postDataKey,
    NameValueCollection postCollection)
    {
    String presentValue = Text;
    String postedValue = postCollection[postDataKey];

    if (presentValue == null || !presentValue.Equals(postedValue)) {
    Text = postedValue;
    return true;
    }

    return false;
    }


    public virtual void RaisePostDataChangedEvent() {
    OnTextChanged(EventArgs.Empty);
    }


    protected virtual void OnTextChanged(EventArgs e) {
    if (TextChanged != null)
    TextChanged(this,e);
    }


    protected override void Render(HtmlTextWriter output) {
    output.Write("<INPUT type= text name = "+this.UniqueID
    + " value = " + this.Text + " >");
    }
    }

    and the OnTextChanged event was fired after the page_load as expected.

    Your code is doing the opposite.

    The reason of my queries was just to understand IPostBackEventHandler and
    IPostBackDataHandler derived custom server control,
    and event fired from them.
    The TextBox is derived from
    public class TextBox : WebControl, IPostBackDataHandler,
    IEditableTextControl, ITextControl.
    The control in your code is derived from the TextBox.
    I still don't understand why your code is doing the opposite as my
    public class MyTextBox: Control, IPostBackDataHandler.

    mike

    "bruce barker (sqlwork.com)"
    <> wrote in message
    news:...
    > you keep asking this, but never say what you are trying to do, making it
    > hard
    > for anyone to give a better answer than sure you can.
    >
    > here is a custom textbox control that the TextChanged event before onload
    > (as soon as postback data is availiable).
    >
    > public class MyTextBox : TextBox
    > {
    > protected override bool LoadPostData(
    > string postDataKey,
    > System.Collections.Specialized.NameValueCollection
    > postCollection)
    > {
    > bool returnValue = base.LoadPostData(postDataKey, postCollection);
    > base.RaisePostDataChangedEvent();
    > return returnValue;
    > }
    > protected override void RaisePostDataChangedEvent(){}
    > }
    >
    > -- bruce (sqlwork.com)
    >
    >
    > "Michal Valent" wrote:
    >
    >> I would like to fire some custom server control event before Page_Load
    >> event
    >> like this (from the trace of an aspx page) :
    >>
    >> Trace Information
    >> Category Message From First(s) From Last(s)
    >> aspx.page Begin PreInit
    >> aspx.page End PreInit 5,38454603734274E-05 0,000054
    >> aspx.page Begin Init 8,96405962016187E-05 0,000036
    >> aspx.page End Init 0,00072941040948794 0,000640
    >> aspx.page Begin InitComplete 0,000772971258380746 0,000044
    >> aspx.page End InitComplete 0,000803692870689425 0,000031
    >> aspx.page Begin LoadState 0,000834735021502791 0,000031
    >> aspx.page End LoadState 0,00178558244517456 0,000951
    >>
    >> aspx.page Begin ProcessPostData 0,00183099373614339 0,000045
    >> customPaging.aspx Grid_PageIndexChanged 0,0109000220370222 0,009069 ---
    >> THE
    >> CUSTOM SERVER CONTROL EVENT FIRED HERE
    >> aspx.page End ProcessPostData 0,0742993505756337 0,063399
    >>
    >> aspx.page Begin PreLoad 0,0743912900339237 0,000092
    >> aspx.page End PreLoad 0,0744449925875471 0,000054
    >> aspx.page Begin Load 0,0744761125357267 0,000031
    >> customPaging.aspx Page_Load 0,0745075526885167 0,000031 --- THE PAGE LOAD
    >> EVENT FIRED HERE
    >> aspx.page End Load 0,0746396646365895 0,000132
    >> aspx.page Begin ProcessPostData Second Try 0,0746623954910917 0,000023
    >> aspx.page End ProcessPostData Second Try 0,0746837463605524 0,000021
    >> aspx.page Begin Raise ChangedEvents 0,0747043760183775 0,000021
    >> aspx.page End Raise ChangedEvents 0,0747389591179849 0,000035
    >> aspx.page Begin Raise PostBackEvent 0,0747599143227289 0,000021
    >> aspx.page End Raise PostBackEvent 0,0747898419344499 0,000030
    >>
    >>
    >>
    >> According to the aspx page lifecycle - the custom server control events
    >> could be fired in the
    >>
    >> aspx.page Begin Raise PostBackEvent 0.099569 0.000043
    >> aspx.page End Raise PostBackEvent 0.489606 0.360924
    >>
    >> PostBackEvent section.
    >>
    >>
    >>
    >> thanks
    >> mike
    >>
    >>
    >>
    Michal Valent, Dec 5, 2007
    #3
    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. bminder
    Replies:
    1
    Views:
    2,166
    nfedin
    Feb 23, 2004
  2. Daves
    Replies:
    10
    Views:
    970
    Brock Allen
    May 11, 2005
  3. Michal Valent
    Replies:
    2
    Views:
    412
    Michal Valent
    Nov 27, 2007
  4. Mark

    Button-click fire before or after page_load?

    Mark, Mar 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    7
    Views:
    209
    Alessandro Zifiglio
    Mar 6, 2004
  5. Guest

    Fire server side event before client side event

    Guest, Mar 17, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    587
    Ken Cox [Microsoft MVP]
    Mar 18, 2005
Loading...

Share This Page