在web的后缀代码中怎么弹出确认框?
在C#的Web后缀代码中有个判断,需要弹出确认框让用户选择,再根据用户选择确认是否继续,这个该怎么做?
我在前台放了一个隐藏控件
<asp:HiddenField ID="hidAmount" runat="server" />
后缀代码如:
protected void Button1_Click(object sender, EventArgs e)
{
//方式一
int a = 10;
int b = 20;
if (a <= b)
{
string strMsg = string.Format("您确定要继续吗?");
string cmd = "<Script Language='JavaScript'>if ( window.confirm('" + strMsg + "')) { $('#'+'" + hidAmount.ClientID + "').val('1') ;} else {$('#'+'" + hidAmount.ClientID + "').val('0') ;};</script>";
if (!this.IsStartupScriptRegistered("hello"))
{
this.RegisterStartupScript("hello", cmd);
}
if (string.IsNullOrEmpty(hidAmount.Value) || string.Equals("0", hidAmount.Value))
{
this.RegisterStartupScript("hello", "<script>alert('continue')</script>");
return;
}
}
但是我这样做的话,程序是执行完所有的后再弹出确认框,请问一下这个该怎么做?
------解决方案--------------------
提交2次。
第一次弹出提示框
第二次 执行弹出框的内容
参考代码
protected void Page_Load(object sender, EventArgs e){
string __EVENTTARGET = Request.Form["__EVENTTARGET"];
string __EVENTTARGET = Request.Form["__EVENTARGUMENT"];
if(__EVENTTARGET == "button" && __EVENTTARGET == "click"){
if (string.IsNullOrEmpty(hidAmount.Value)
------解决方案--------------------
string.Equals("0", hidAmount.Value))
{
this.RegisterStartupScript("hello", "<script>alert('continue')</script>");
return;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
//方式一
int a = 10;
int b = 20;
if (a <= b)
{
string strMsg = string.Format("您确定要继续吗?");
string cmd = "<Script Language='JavaScript'>if ( window.confirm('" + strMsg + "')) { $('#'+'" + hidAmount.ClientID + "').val('1') ;} else {$('#'+'" + hidAmount.ClientID + "').val('0') ;};__doPostBack('button','click')</script>";
if (!this.IsStartupScriptRegistered("hello"))
{
this.RegisterStartupScript("hello", cmd);
}
}