我想事件处理程序分配给ASP按钮点击ASP.Net分配事件处理程序ASP按钮点击
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<div>
<asp:Table id="tb" runat="server" Height="239px" Width="417px" >
</asp:Table>
</div>
<table>
<tr>
<td></td><td><asp:Button ID="Votes" runat="server" Text="Vote" OnClick="Votes_Click" /></td>
</tr>
</table>
</asp:Content>
但调试项目时,点击上面的按钮,它执行Page_Load事件不Votes_Click事件
为什么它这样做? 以及如何解决这个问题?
和代码隐藏页的手柄是
protected void Votes_Click(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "btn",
"<script type = 'text/javascript'>alert('Button Clicked');</script>");
int i = 0;
Response.Redirect("Default.aspx");
}
页面始终执行Page_Load处理程序 - 它是页面生命周期的一部分。它在那之后执行控制事件。您可以在'Votes_Click'处理程序中放置断点,并在*页面加载后查看它是否已经到达*? – 2013-05-12 14:07:14