Asp.Net后台弹出确认提示窗Confirm
程序员文章站
2023-10-31 18:10:40
前端js代码: 后台C#代码: ......
前端js代码:
function myconfirm(message, guid) { if (confirm(message) == true) { document.getelementbyid("hidden1").value = guid; } else { document.getelementbyid("hidden1").value = ""; } //form1.submit(); form1.submit(); }
后台c#代码:
1 /// <summary> 2 /// 用于标识confirm是否继续当前操作 3 /// </summary> 4 public string confirmvalue 5 { 6 get { return viewstate["confirmvalue"] == null ? "" : viewstate["confirmvalue"].tostring(); } 7 set { viewstate["confirmvalue"] = value; } 8 } 9 10 protected void page_load(object sender, eventargs e) 11 { 12 if (!string.isnullorempty(confirmvalue)) 13 { 14 btnsave_click(null, null);//后台弹出确认对话框 15 } 16 if (ispostback) 17 { 18 return; 19 } 20 } 21 22 protected void btnsave_click(object sender, eventargs e) 23 { 24 25 26 if (string.isnullorempty(confirmvalue))//提示 27 { 28 string strguid = guid.newguid().tostring(); 29 confirmvalue = strguid; 30 scriptmanager.registerstartupscript(this, this.gettype(), "_showmessage", "myconfirm('是否继续?','" + strguid + "');", true); 31 return; 32 } 33 if (!string.isnullorempty(confirmvalue) && confirmvalue != hidden1.value)//取消 34 { 35 confirmvalue = ""; 36 //showmessage("提示", "您取消了当前操作"); 37 return; 38 } 39 else//如果点击确认,则需要把confirmvalue初始化为空 40 { 41 confirmvalue = ""; 42 } 43 } 44 45 46 47 48