Click here to Skip to main content
15,353,587 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
C#
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
}

    }
       }


Please help me.I am facing lots of problem for this solution please please help me .Thanks in advance
shibashish mohanty
Posted
Updated 6-Oct-21 22:29pm
v4
Comments
Ganesan Senthilvel 2-Jul-12 6:46am
   
What is the error you are getting?
AshishChaudha 2-Jul-12 6:51am
   
where you are getting exception??
Sebastian T Xavier 2-Jul-12 7:37am
   
please don't repost
Siva Hyderabad 8-Feb-14 0:48am
   
hai
Siva Hyderabad 8-Feb-14 0:52am
   
your problem is solved in this situvation

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


In ImageBtnSave_Click

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

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



In callMethodForRegisteringTheConfirmDialog(GradeName)

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



add this in the JS file - showConfirm(Grade)

C#
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;
}


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

C#
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
   
v2
Comments
[no name] 2-Jul-12 7:09am
   
Then whats the use of confirmation.in both case it will executes all code
Shemeer NS 2-Jul-12 16:17pm
   
I have updated the answer with another solution.
MadiceNL 4-Mar-15 9:17am
   
Nice solution, but postback wasn't working from script. Found out that UniqueID should be used instead of ClientID. (see http://codeverge.com/asp.net.ajax-ui/updatepanel-dopostback-mycontrol.clientid-doe/234449)
XML
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.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900