UserControl "PreRender" Event

Discussion in 'ASP .Net Web Controls' started by Alex Maghen, Jun 30, 2009.

  1. Alex Maghen

    Alex Maghen Guest

    I am building a C# Web UserControl. By default, when you create one in VS, it
    comes with the

    protected void Page_Load(object sender, EventArgs e)

    event handler set up. How do I add an Event Handler function for other
    events (such as PreRender)? Now that I think of it, where is the "wiring"
    that creates the "Page_Load" EventHandler in the first place?

    Thanks.

    Alex

    -----------------------------------------------------------------------------
    Less Spam Better enjoyable experience
    Visit : news://spacesst.com
    Alex Maghen, Jun 30, 2009
    #1
    1. Advertising

  2. Hello Alex,

    You can define every event of page directly in code behind.


    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Page_PreInit(object sender, EventArgs e)
    {

    }

    protected void Page_PreRender(object sender, EventArgs e)
    {

    }

    In VB.Net, there is a list to show every event of page on the right side of
    VS.
    In C#, there isn't a shootcut like this to do. But there is a workround to
    build this kind of event:
    For example, you can type "Page." in Page_Load event, it will autocomplete
    to show every attributes and event of page instance. Then you can select
    one of the events it lists. Assuming that you select PreRender event, it
    will show Page.PreRender. After that, you can input "+=". It will prompt
    you press "Tab" key to insert the event handler. Then you can press "Tab"
    key, it will generate "Page.PreRender+=new EventHandler(Page_PreRender);"
    automatically, and when you press "Tab" once more, it will generate the
    event handler as below if this event handler is not defined.
    void Page_PreRender(object sender, EventArgs e)
    {
    throw new NotImplementedException();
    }

    Append "protected" before "void".

    protected void Page_PreRender(object sender, EventArgs e)
    {
    //throw new NotImplementedException();
    }

    At last, don't forget to remove "Page.PreRender+=new
    EventHandler(Page_PreRender);" what we built in Page_Load. We don't need it
    any more.

    That is a workround to build an Event Handler in C#.


    Sincerely,

    Vince Xu

    Microsoft Online Support


    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

    MSDN Managed Newsgroup support offering is for non-urgent issues where an
    initial response from the community or a Microsoft Support Engineer within
    2 business day is acceptable. Please note that each follow up response may
    take approximately 2 business days as the support professional working with
    you may need further investigation to reach the most efficient resolution.
    The offering is not appropriate for situations that require urgent,
    real-time or phone-based interactions. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    ==================================================


    --------------------
    | Thread-Topic: UserControl "PreRender" Event
    | thread-index: Acn5IQdq1rBUpSMKTlGxhcleCDg0PA==
    | X-WBNR-Posting-Host: 216.205.224.10
    | From: =?Utf-8?B?QWxleCBNYWdoZW4=?= <>
    | Subject: UserControl "PreRender" Event
    | Date: Mon, 29 Jun 2009 18:21:01 -0700
    | Lines: 12
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3168
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | Path: TK2MSFTNGHUB02.phx.gbl
    | Xref: TK2MSFTNGHUB02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:4771
    | NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    |
    | I am building a C# Web UserControl. By default, when you create one in
    VS, it
    | comes with the
    |
    | protected void Page_Load(object sender, EventArgs e)
    |
    | event handler set up. How do I add an Event Handler function for other
    | events (such as PreRender)? Now that I think of it, where is the "wiring"
    | that creates the "Page_Load" EventHandler in the first place?
    |
    | Thanks.
    |
    | Alex
    |


    -----------------------------------------------------------------------------
    Less Spam Better enjoyable experience
    Visit : news://spacesst.com
    Vince Xu [MSFT], Jun 30, 2009
    #2
    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. =?Utf-8?B?QWxpcmV6YSBaaWFp?=

    PreRender Event occurs immediatley after Load event

    =?Utf-8?B?QWxpcmV6YSBaaWFp?=, Feb 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,096
    Hans Kesting
    Feb 9, 2004
  2. Jimmy
    Replies:
    5
    Views:
    15,218
    =?Utf-8?B?Sm9yZ2UgTCBNYXRvcyBbTUNTRC5ORVRd?=
    Apr 27, 2005
  3. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    166
  4. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    174
    vatech1993
    Dec 11, 2004
  5. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    141
Loading...

Share This Page