Handling events in .ASPX file not in .CS
I have a problem that 开发者_开发问答how can i handle control's events in .ASPX file. For example if there is server Button control then my requirement is how to handle its click event in .ASPX file. I have compulsion to not use .cs file so there is no code behind file. Any help is appreciated.
You want to use the Single-File Page Model.
See http://msdn.microsoft.com/en-us/library/015103yb.aspx#Y224
Example:
<%@ Page Language="C#" %>
<script runat="server">
void Button1_Click(Object sender, EventArgs e)
{
Label1.Text = "Clicked at " + DateTime.Now.ToString();
}
</script>
<html>
<head>
<title>Single-File Page Model</title>
</head>
<body>
<form runat="server">
<div>
<asp:Label id="Label1"
runat="server" Text="Label">
</asp:Label>
<br />
<asp:Button id="Button1"
runat="server"
onclick="Button1_Click"
Text="Button">
</asp:Button>
</div>
</form>
</body>
</html>
精彩评论