Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

how to fire custom server control events before Page_Load event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michal Valent - 04 Dec 2007 16:27 GMT
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) - 04 Dec 2007 17:22 GMT
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)

> I would like to fire some custom server control event before Page_Load event
> like this (from the trace of an aspx page) :
[quoted text clipped - 38 lines]
> thanks
> mike
Michal Valent - 05 Dec 2007 09:27 GMT
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

> you keep asking this, but never say what you are trying to do, making it
> hard
[quoted text clipped - 63 lines]
>> thanks
>> mike

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.