i was wondering if we can get the events of a asp or html element out of the form tag ?
default.aspx :
<head runat="server">
<link href="CSS/main.css" rel="stylesheet" type="text/css" />
<title>test title</title>
</head>
<body>
<script>
this.
</script>
<div class="container">
<a id="aOnHtml" runat="server">Test</a>
<button id="btnID" runat="server" onclick="btnClicked" > BTN </button>
</div>
</body>
</html>
and default.aspx.cs :
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
btnID.ServerClick += new EventHandler(this.btnClicked);
}
void btnClicked(Object sender , EventArgs e)
{
aOnHtml.InnerText = "Clicked";
}
}
i have break point at the begging of btnClicked function which it doesn't get there at all ,what is the problem ?
You are missing the basic form element which you need to make this work. Take a look at this : http://www.w3schools.com/aspnet/aspnet_forms.asp
您要做的是:1.使用<asp:button>
代替<button>
2.获得btnID.Click
或btnID.ClientClick
而不是btnID.ServerClick
,一切都会好起来。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.