asp.net代码中的确认消息框背后 [英] Confirmation Message Box in asp.net code behind

查看:58
本文介绍了asp.net代码中的确认消息框背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void ImageBtnSave_Click(object sender, ImageClickEventArgs e)
       {
          string gradename="";
      UHRMS_PayGradeList objsalry = new UHRMS_PayGradeList();
      List<UHRMS_PayGradeList> Grade = new List<UHRMS_PayGradeList>();
      objsalry.Operation = "selectExistingsalary";
      objsalry.SalaryBetn = Convert.ToDecimal(TxtMinSal.Text);
      Grade = ERPManagement.GetInstance.GetExistingSalary(CompanyID, objsalry);
      if (Grade.Count != 0)
      {
          gradename = Grade[0].Pay_Grade_Name;
      }
      if (gradename != "")
      {
          ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "confirm('You are overriding the existing pay grade " + gradename.ToString() + ". Do you want to Override " + gradename.ToString() + " ?');", true);


//My doubt is this
If(ok button clicked)
{
 insertPayGrade();
}
else
{
//do not insert
}

    }
       }





请帮帮我。我面临很多问题请帮帮我。谢谢。

shibashish mohanty



Please help me.I am facing lots of problem for this solution please please help me .Thanks in advance
shibashish mohanty

推荐答案

我想说最好的选择是将你的代码分成多个代码块





ImageBtnSave_Click



I would say the best option is to split your code into mutliple code blocks


In ImageBtnSave_Click

callMethodForCalculatingTheGrade();//  put the before the register script

If(condition)
     callMethodForRegisteringTheConfirmDialog(GradeName); //put the register script code in this method







在callMethodForRegisteringTheConfirmDialog(GradeName)






In callMethodForRegisteringTheConfirmDialog(GradeName)

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "script", "showConfirm('" + GradeName + " ');", true);







在JS文件中添加 - showConfirm(等级)






add this in the JS file - showConfirm(Grade)

function showConfirm(Grade) {
        if (confirm("You are about to overrite the existing pay grade, contine overriting?") == true) {
            __doPostBack('<%= this.cmdOverriteGrade.ClientID %>', "true");
            return false;
        }
        return false;
}





在HTML源代码中添加此虚拟控件添加此控件





add this dummy control in the HTML source add this control

<asp:Button ID="cmdOverriteGrade" runat="server" Style="display: none;" OnClick="cmdOverriteGrade_Click" /> 




源代码中的
处理我们的虚拟按钮的点击事件





in source code handle the click event of our dummy button

protected void cmdOverriteGrade_Click(object sender, EventArgs e)
{
    try
    {
            string confirmResult = (this.Request["__EVENTARGUMENT"] == null) ? string.Empty : this.Request["__EVENTARGUMENT"];
            if (confirmResult == "true")
            {
                //do the insert code
            }
    }
    catch (Exception ex){
    }
}





如果它回答你的问题就标记为解决方案



mark as solution if it answer your question


1) Form Design

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <script type = "text/javascript">
        function Confirm() {
            var confirm_value = document.createElement("INPUT");
            confirm_value.type = "hidden";
            confirm_value.name = "confirm_value";
            if (confirm("Do you want to save data?")) {
                confirm_value.value = "Yes";
            } else {
                confirm_value.value = "No";
            }
            document.forms[0].appendChild(confirm_value);
        }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
      <asp:Button ID="btnConfirm" runat="server"

     OnClick = "OnConfirm" Text ="Raise Confirm" OnClientClick = "Confirm()"/>
    </form>
    </body>
    </html>


2) Codebehind



    public void OnConfirm(object sender, EventArgs e)
    {
    string confirmValue = Request.Form["confirm_value"];
    if (confirmValue == "Yes")
    {
    this.Page.ClientScript.RegisterStartupScript(this.GetType(),"alert('You    clicked YES!')", true);
    }
    else
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
    }
    }


3) When you click the delete button confirmation box will be displayed.

4) If you click ok then OK part will work in code else No Part

5) The same method in GRIDVIEW DELETE BUTTON.


HI,

你可以使用下面的javascript


You can use the below javascript
引用:

函数Confrimdelete(strHierarchyCode){

var del;

del = confirm(你确定要删除+ strHierarchyCode);

if(del){

返回true;

}

else {

return false;

}



}

function Confrimdelete(strHierarchyCode) {
var del;
del = confirm("Are you sure you want to delete " + strHierarchyCode);
if (del) {
return true;
}
else {
return false;
}

}



谢谢

< a href =http://www.alacraft.com.au/wall-stickers-cat32>墙贴


这篇关于asp.net代码中的确认消息框背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆