为何aspx页面 刷新自动执行Button中的OnClick事件?怎么禁止?
aspx前台代码:<body><formid="form1"runat="server"><div><asp:LabelID="Label1"runat="server"...
aspx前台代码:
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
aspx后台代码如下:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('123');</script>");
}
} 展开
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
aspx后台代码如下:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('123');</script>");
}
} 展开
1个回答
展开全部
你执行过一次以后再刷新,当然会再次提交 。。。 除非你用GET方法,不然没什么方法
追问
是的,GET方法怎么用啊?
追答
<body>
<form runat="server" id="form1" method="get">
<input id="Text1" name="txtYourName" type="text" />
<input id="Submit1" type="submit" value="submit" />
</form>
</body>
后台:
private void Page_Load(Object sender,eventArgs e)
{
String reqYourName=request["txtYourName"];
if(!String.IsNullOrEmpty(reqYourName))
{
Response.write("Hello : " + reqYourName);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询