Creating event for ASP.NET Server Control in VS from Source View
Is it possible to 开发者_如何学运维create Event (for example Button click event) from Source View? I mean without going to design view ?
In your code, you create your method:
protected void Button1_Click(object sender, EventArgs e)
{
}
And in your markup (not the design view), you add your button:
<asp:Button runat="server" OnClick="Button1_Click" />
That should be it.
Additionally you can add an event handler dynamically in Codebehind f.e.(VB.Net):
AddHandler Me.Button1.Click, AddressOf Me.Button1_Click
You need to create an eventhandler and assign a method to it.
ButtonId.click += new EventHandler(Button1_Click);
protected void Button1_Click(object sender, EventArgs e)
{
}
精彩评论