Click here to Skip to main content
15,791,564 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
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)
//do not insert


Please help me.I am facing lots of problem for this solution please please help me .Thanks in advance
shibashish mohanty
Updated 6-Oct-21 23:29pm
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    
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

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

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

In callMethodForRegisteringTheConfirmDialog(GradeName)

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

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;

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)
            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
Share this answer
[no name] 2-Jul-12 7:09am    
Then whats the use of 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
1) Form Design

    <html xmlns="">
    <script type = "text/javascript">
        function Confirm() {
            var confirm_value = document.createElement("INPUT");
            confirm_value.type = "hidden";
   = "confirm_value";
            if (confirm("Do you want to save data?")) {
                confirm_value.value = "Yes";
            } else {
                confirm_value.value = "No";
    <form id="form1" runat="server">
      <asp:Button ID="btnConfirm" runat="server"
     OnClick = "OnConfirm" Text ="Raise Confirm" OnClientClick = "Confirm()"/>

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);
        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.
Share this answer

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