This is a migrated thread and some comments may be shown as answers.

Need to show Confirm window through code behind

4 Answers 209 Views
Window
This is a migrated thread and some comments may be shown as answers.
Mohan
Top achievements
Rank 1
Mohan asked on 21 Jul 2012, 10:45 AM
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.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Jul 2012, 06:10 AM
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.
0
Mohan
Top achievements
Rank 1
answered on 23 Jul 2012, 08:26 PM
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


0
Princy
Top achievements
Rank 2
answered on 24 Jul 2012, 06:17 AM
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.
0
Mohan
Top achievements
Rank 1
answered on 24 Jul 2012, 08:55 AM
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
Tags
Window
Asked by
Mohan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mohan
Top achievements
Rank 1
Share this question
or