Confirm Box and Result in Code-behind

8 posts, 0 answers
  1. Mikhail
    Mikhail avatar
    10 posts
    Member since:
    May 2008

    Posted 28 Jan 2009 Link to this post

    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?

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Jan 2009 Link to this post

    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.
  3. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 29 Jan 2009 Link to this post

    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.
  4. SKS
    SKS avatar
    32 posts
    Member since:
    Aug 2009

    Posted 29 Jan 2010 Link to this post

    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
  5. illumination
    illumination avatar
    85 posts
    Member since:
    May 2008

    Posted 01 Apr 2010 Link to this post

    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.
  6. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 06 Apr 2010 Link to this post

    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.
  7. Jay
    Jay avatar
    10 posts
    Member since:
    Sep 2008

    Posted 22 Jan 2012 Link to this post

    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

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

    Posted 22 Jan 2012 Link to this post

    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.
Back to Top