|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
UserControl "PreRender" EventI 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 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 ================================================== -------------------- Show quoteHide quote | Thread-Topic: UserControl "PreRender" Event microsoft.public.dotnet.framework.aspnet.webcontrols:4771| thread-index: Acn5IQdq1rBUpSMKTlGxhcleCDg0PA== | X-WBNR-Posting-Host: 216.205.224.10 | From: =?Utf-8?B?QWxleCBNYWdoZW4=?= <AlexMaghen@newsgroup.nospam> | Subject: UserControl "PreRender" Event | Date: Mon, 29 Jun 2009 18:21:01 -0700 | Lines: 12 | Message-ID: <7A8436D4-4517-4DD1-B6F7-0B316471D***@microsoft.com> | 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 Show quoteHide quote | 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 | |
|||||||||||||||||||||||