开发者

Creating event for ASP.NET Server Control in VS from Source View

开发者 https://www.devze.com 2023-01-02 01:14 出处:网络
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:

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)
{

}
0

精彩评论

暂无评论...
验证码 换一张
取 消