Need to show Confirm window through code behind

5 posts, 0 answers
  1. Mohan
    Mohan avatar
    17 posts
    Member since:
    Jun 2012

    Posted 21 Jul 2012 Link to this post

    Team,

    I have a scenario to ask for confirmation before proceeding the logic. I need to call the confirm in TextBox Changed Event at code-behind (C#).

    CS
    RadAjaxManager1.ResponseScripts.Add("radconfirm('Are you sure!?', confirmCallBackFn);");

    How can i get the result value if I press Yes or No, need some sample script.

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Jul 2012 Link to this post

    Hi Mohan,

    Radconfirm just as the standard confirm works on the client. Therefore, to perform any actions on the server side after you select Yes/No, you need to make a postback to the server.You can do this by placing invisible server buttons on your page and then in the JavaScript callback function of radconfirm to invoke the "click" event of the button which will cause a postback. Then, in the event handler of the button you can perform the server side actions. Try the code snippets below.

    ASPX:
    <asp:Button ID="Button1" runat="server" CssClass="buttons"  Text="Button" onclick="Button1_Click" />
    <asp:Button ID="Button2" runat="server" CssClass="buttons"  Text="Button" onclick="Button2_Click" />

    CSS:
    <style type="text/css">
     .buttons
     {
      display:none;
     }
    </style>

    Javascript:
    function confirmCallBackFn(arg)
    {
     if (arg == true)
     {
      document.getElementById("Button1").click();
     }
     else
     {
      document.getElementById("Button2").click();
     }
    }

    C#:
    protected void Button1_Click(object sender, EventArgs e)
    {
      // Your code for "YES"
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
      // Your code for "No"
    }

    Thanks,
    Princy.
  3. Mohan
    Mohan avatar
    17 posts
    Member since:
    Jun 2012

    Posted 23 Jul 2012 Link to this post

    Princy,

    Thanks for your reply, I have tried this code, and getting Java script error. In the server side i use the method like below

            protected void Yes_Click(object sender, EventArgs e)
            {
                ViewState["AddDay"] = "1";
                ViewState["AddDate"] = ""; // scheduleDateTM;
                ViewState["IsInDate"] = "true";
                ViewState["IsOutDate"] = "true";
                tbInDate.Text = String.Format(CultureInfo.InvariantCulture, "{0:" + DateFormat + "}", newTime.AddDays(1));
            }

            protected void No_Click(object sender, EventArgs e)
            {
                // Your code for "No"
            }
    This method is not firing. I am having Nested Master Pages. Please check the screen shot of the error.

    Thanks


  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Jul 2012 Link to this post

    Hi Mohan,

    Try accessing the button from master page as follows.

    Javascript:
    <script type="text/javascript">
    function confirmCallBackFn(arg)
    {
     if (arg == true)
     {
      document.getElementById('<%= Page.Master.FindControl("ContentPlaceHolder1").FindControl("Button1").ClientID %>').click();
     }
    }
    </script>

    Hope this helps. 

    Thanks,
    Princy.
  5. Mohan
    Mohan avatar
    17 posts
    Member since:
    Jun 2012

    Posted 24 Jul 2012 Link to this post

    Princy,

    Thanks for the reply, When using find control it display's null, so I changed like below. Now it's working fine

                function confirmCallBackFn(arg) {
                    if (arg == true) {
                          document.getElementById("ctl00_ctl00_MainContent_BodyContent_btnYes").click();
                    }
                }

    Regards
    Mohan
Back to Top