radprompt calls callback even when 'Cancel' is clicked

7 posts, 0 answers
  1. mlandauer
    mlandauer avatar
    17 posts
    Member since:
    Mar 2007

    Posted 01 Jul 2008 Link to this post

    With versions 2008 Q1 SP1 & SP2, the radprompt calls the callback function regardless of whether 'OK' or 'Cancel' is clicked.  In prior versions the callback would not be called if 'Cancel' was clicked.  How do I know if the user clicked 'OK' or 'Cancel'?
  2. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 03 Jul 2008 Link to this post

    Hello mlandauer,

    Indeed, this is intended behavior. The callback function passes true or false as an argument depending on what the user has clicked. For more information you can check the example in our online demos:
    http://www.telerik.com/DEMOS/ASPNET/Prometheus/Window/Examples/BrowserDialogBoxes/DefaultCS.aspx





    Regards,
    Georgi Tunev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. mlandauer
    mlandauer avatar
    17 posts
    Member since:
    Mar 2007

    Posted 03 Jul 2008 Link to this post

    It appears when "Cancel" is clicked, it passed an empty string as the argument to the callback.  How do I differentiate this from the user clicking "OK" with nothing in the textbox?  I need to be able to tell the difference.
  4. mlandauer
    mlandauer avatar
    17 posts
    Member since:
    Mar 2007

    Posted 03 Jul 2008 Link to this post

    I found a temporary workaround.  Setting the <prompttemplate> of my RadWindowManager to a copy of the code in CoreTemplates.xml handles cancel properly.
  5. mlandauer
    mlandauer avatar
    17 posts
    Member since:
    Mar 2007

    Posted 13 Aug 2008 Link to this post

    An answers as far as how to tell the difference between the user clicking "Cancel" the user clicking "OK" with the text box empty?
  6. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 14 Aug 2008 Link to this post

    Hello mlandauer,

    Indeed, this is an omission from our side - when cancel is clicked, the dialog should return null.

    Thank you for bringing this problem to our attention - we will fix it for the Service Pack and for now you can modfy the prompttemplate and return null as an argument:

    <div> 
        <id="OKbtn_{0}" onclick="$find('{0}').callBack(this.parentNode.parentNode.getElementsByTagName('input')[0].value);"                
            class="radwindowbutton" href="javascript:void(0);" ><span class="outerspan"><span class="innerspan">##LOC[OK]##</span></span></a> 
        <onclick="$find('{0}').callBack(null);" class="radwindowbutton"  href="javascript:void(0);"><span class="outerspan"><span class="innerspan">##LOC[Cancel]##</span></span></a> 
    </div> 


    For convenience I attached a sample page that shows this approach. I also updated your points for bringing this problem to our attention.


    All the best,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. kd345205
    kd345205 avatar
    3 posts
    Member since:
    Mar 2009

    Posted 21 Aug 2009 Link to this post

    I have a decent workaround i wanted to share. I am using a radprompt to collect a string from a user then processing it from code behind when "OK" is selected. The way i handled the cancel issues to deal with the argument being null. My code is below with brief explanations. Hope this helps someone.

    .aspx page -

    ...html content...

    <

     

    asp:ImageButton ImageAlign="Bottom" runat="server" ID="AddNewImg" OnClientClick="promptFn(); return false;" ImageUrl="~/images/add_user.png" Height="24" Width="24" />

     

    <script type="text/javascript">
    function openRadWin()

     

    {

    radopen(

     

     

    "","RadUploadWindow");

    }

     

    function promptFn()

     

     

    {

    radprompt(

    "<p>Enter new client name:</p>", promptCallBackFn, 330, 160, null, "Client Entry"); 

     

     

     

    return false;

    }

     

    function promptCallBackFn(arg)

    {

    PageMethods.AddNewClient(arg, ShowResult);

    }

     

    function ShowResult(arg)

    {

    radalert (

     

    "Result: <h3 style='color: #ff0000;'>" + arg + "</h3>",null,null, "Results");

    }

    </script>

     

     

     

    ok so at this poing we have an image button that has a clientside onclick event to call "promptFn()" which uses the following page method from code-behind:

    [

    WebMethod]

     

     

    public static string AddNewClient(string name)

     

    {

    if (name == nullreturn "Action Canceled"; //THIS IS KEY!! WHEN CANCEL IS CLICKED THE RETURN ARG IS NULL SO THE STRING PASSED IS NULL

     

     

     

     

     

    if (name.Length > 0)

    {

     

    if (!Directory.Exists(mypath + "/Clients/" + name)) //SINCE YOU CANT USE SERVER.MAPPATH I DECLARED A STATIC VAR AND

    {                                                                             //DEFINED IT IN THE PAGE_LOAD EVENT

     

    Directory.CreateDirectory(mypath + "/Clients/" + name);
    if (Directory.Exists(mypath + "/Clients/" + name))

     

    {

    return "Success"; }

     

     

     

    else{return "Error: Duplicate entry."; }

     

    }

     

     

    else{return "Error: Already Exists.";}

     

    }

     

     

    else{return "Error: No name entered.";}

     

    }

    The result of this is the following:

    User clicks on "add client image" and you get radprompt "enter new client name" now...
    1) user clicks ok with text in box
        a) code behind gets the client name string as an argument and processes because it has a length > 0
        b) returns string depending on if there is a duplicate or not
        c) Result shown by radalert box
    2)User clicks ok with no text
        a) code behind gets blank string as argument
        b) returns a "NO NAME ENTERED" string
        c) result shown by radalert box
    3) User clicks cancel
        a) a null string is passed to code behind
        b) returns a string to say it was canceled
        c) radalert shows "CANCELED ACTION"

    **DONT FORGET TO USE:

     

    <

     

    asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> <-----YOU MUST HAVE THIS SET TO TRUE

     

     

    </asp:ScriptManager>

     

     

    Cheers,
        Kiel

Back to Top