C#问题-web应用程序(跳转页面的问题)

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("<script>alert('你已提交答案')</script>");
Response.Redirect("WebForm1.aspx");
}
为什么不会弹出对话框的??
怎么解决??
高手不吝赐教
那你能不能告诉我
Response.Write("<script>confirm('你确定要提交答案?')</script>");
怎样判断是否按了确认!
2楼你的Button1_Click事件怎么写的

楼上回答错误,吼吼~

在page_load里加入注册脚本语句:
Button1.Attributes.Add("onclick","<script>if(!window.confirm('你确定要提交答案?')){window.event.returnValue=false;}</script>");

Button1_Click事件里照常写提交答案的那块逻辑就行了。

因为按钮总是先看是否有它的客户端事件,有就先执行,再去看有无服务器端事件,有就继续回传服务器执行。
上述语句在客户端弹出一个Confirm,当Confirm选择取消时,把event.returnValue设成false,程序将默认没有点击此按钮,所以就不再执行服务器端的代码了。

怎么样,这个回答满意不?
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-01-11
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("<script>alert('你已提交答案');location='WebForm1.aspx'</script>");
}
第2个回答  2008-01-12
帖另外一种方法给你:
public static void ShowMessageboxAndLocation(string p_strMsg, string LocationUrl)
{
string m_strJava = "<script>javascript:window.alert(\"{0}\");;window.location.href=\"{1}\";</script>";
m_strJava = String.Format(m_strJava, p_strMsg, LocationUrl);
WriteToClient(m_strJava);
}
public static void WriteToClient(string p_strJava)
{
HttpContext.Current.Response.Write(p_strJava);
}
相似回答