Automatically create event handler from markup view (C #)
Can Visual Studio automatically create an event handler method for a UI component in markup view?
Let's say I have
<asp:label runat="server" />
and would like to handle the OnPreRender event.
How do you create a handler method? Manually or do you switch to design view and double-click the event in the properties window?
a source to share
You can automatically create a handler method by going to the OnLoad page or Page_Load method and adding a handler for the event. For example, for this label:
<asp:label ID="MyLabel" runat="server" />
You would do this:
protected void OnLoad(object sender, EventArgs e)
{
MyLabel.PreRender +=
}
At this point, IntelliSense should start and suggest generating an event handler for you. If you hit TAB twice, you should have a new method called MyLabel_PreRender.
Good luck!
a source to share
Take a look at this msdn link: http://msdn.microsoft.com/en-us/library/6w2tb12s%28v=VS.90%29.aspx (VS 2008 version)
It says that you can create a method declaratively named Page_event.
For example, to create a handler for the page load event, create a method named Page_Load.
ASP.NET pages automatically bind page events to methods that are named Page_event. This autobinding is configured by the AutoEventWireup attribute in the @Page directive, which is set to true by default. If AutoEventWireup is set to false, the page will not automatically look for methods that use the Page_event naming convention.
Worked for me!
a source to share