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

Confirm Box and Result in Code-behind

7 Answers 930 Views
Window
This is a migrated thread and some comments may be shown as answers.
Mikhail
Top achievements
Rank 1
Mikhail asked on 29 Jan 2009, 12:17 AM
Hello fellas,
I've been trying to find a way to get the result of a confirmation box in my code-behind but to no avail.  
I have this javascript that opens the confirm box:

 

function openConfirmBox()

 

{

radconfirm(

'Are you sure?', confirmCallBackFn, 330, 100, null,'Confirm');

 

 

return false;

 

}

the call back function is:

 

 

function confirmCallBackFn(arg)

 

{

radalert(

"" + arg + " is returned.",330,100, "Result");

 

}

But I want the result (arg) to be caught in the code-behind... How do I go about doing this?

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Jan 2009, 05:58 AM
Hi Mikhail,

RadConfirm is 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 an invisible server button on your page and then in the JavaScript callback function of RadConfirm, execute the __doPostBack() of the button which will cause a postback. Then, in the RaisePostBackEvent() event you can perform the server side actions. Try the example below.

ASPX:
<style type="text/css"
.buttons 
    display:none; 
</style> 
<asp:Button ID="Button2" runat="server" CssClass="buttons"  Text="Button" /> 
 

JavaScript:
<script language="javascript" type="text/javascript"
function openConfirmBox() 
    radconfirm('Are you sure?', confirmCallBackFn, 330, 100, null,'Confirm'); 
    return false
function confirmCallBackFn(arg) 
    __doPostBack("<%= Button2.ClientID %>", arg); 
</script> 

CS:
protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument) 
    if (source == Button2 && eventArgument == "true"
        Response.Write("True"); //RadConfirm result - True 
    else if (source == Button2 && eventArgument == "false"
        Response.Write("False"); // RadConfirm result - False 
     

Thanks,
Shinu.
0
Georgi Tunev
Telerik team
answered on 29 Jan 2009, 09:48 AM
Hello Mikhail,

radalert, radprompt and radconfirm are called and handled on the client only - just like the standard alert, prompt and confirm dialogs from the browser.
Note that once you receive the argument on the client, you can perform a postback in the javascript handler by using the built - in javascript __doPostBack function - you can find more information about it here. As an alternative you can also perform an ajax request if this is suitable for your scenario because this will make the page performance better and the unpleasant flickering when loading the page after a postback will disappear. You can do this by using the RadAjaxManager control and its ajaxRequest function .

All the best,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
SKS
Top achievements
Rank 1
answered on 29 Jan 2010, 09:28 PM
hey
this code doesnt work.
i am surprised telerik doesnt have a solution for this.
this is my scenario

i have an aspx page that has a button
the button click opens another aspx page in a radwindow
the radwindow has a button that has a server side handler in code behind.
when this button is clicked
some server side code needs to execute(in the code behind)
in the server side code if a condition is yes then this Radwindow has to open a radconfirm
based on the user reponse on the radconfirm
if Yes-Execute some server side code again
If No-dont do anything

to summarise

its a radconfirm in a radwindow and it needs to be invoked from code behind and the user response needs to be captured in code  behind and execute server side code based on the user response.

i have gone thru 100's of forums for this issue but it amazes me that telerik does not have a neat and clean solution for this.

Any help from shinu is greatly appreciated

thanks

~sks
0
illumination
Top achievements
Rank 2
answered on 01 Apr 2010, 08:20 PM
I am using telerik version 2010.1.309.35 and looking for this same scenario solution. In addition, I need to pull all information from the add page, to radwindow, confirm yes or no then submit. Anybody has solved this problem? Pointers will be appreciated.
Thank you.
0
Georgi Tunev
Telerik team
answered on 06 Apr 2010, 10:34 AM
Hello illumination,

This issue is not related to the radconfirm dialog but is a general programming task. In addition to my reply from 1/29/2009, I would suggest to check the following Code Library article submitted by a customer of ours - please note however that this is a custom solution and we do not support it.
http://www.telerik.com/community/code-library/aspnet-ajax/window/server-side-msgbox-user-control-for-radconfirm-radalert-and-radprompt.aspx


All the best,
Georgi Tunev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jay
Top achievements
Rank 1
answered on 22 Jan 2012, 06:33 PM
Hi Shinnu,
I am trying to use your sample code. I am getting an error message while running the page. Using Q3 2011

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

regards
Jay

0
Princy
Top achievements
Rank 2
answered on 23 Jan 2012, 05:12 AM
Hello,

Here are some links to documents which explain about the same error and how to solve it:
The Controls collection cannot...
RadCodeBlock and RadScriptBlock

Thanks,
Princy.
Tags
Window
Asked by
Mikhail
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Georgi Tunev
Telerik team
SKS
Top achievements
Rank 1
illumination
Top achievements
Rank 2
Jay
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or