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

radprompt calls callback even when 'Cancel' is clicked

6 Answers 174 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
mlandauer
Top achievements
Rank 1
mlandauer asked on 01 Jul 2008, 08:32 PM
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'?

6 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 03 Jul 2008, 08:44 AM
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
0
mlandauer
Top achievements
Rank 1
answered on 03 Jul 2008, 05:34 PM
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.
0
mlandauer
Top achievements
Rank 1
answered on 03 Jul 2008, 07:38 PM
I found a temporary workaround.  Setting the <prompttemplate> of my RadWindowManager to a copy of the code in CoreTemplates.xml handles cancel properly.
0
mlandauer
Top achievements
Rank 1
answered on 13 Aug 2008, 11:20 PM
An answers as far as how to tell the difference between the user clicking "Cancel" the user clicking "OK" with the text box empty?
0
Georgi Tunev
Telerik team
answered on 14 Aug 2008, 08:10 AM
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.
0
kd345205
Top achievements
Rank 1
answered on 21 Aug 2009, 06:56 PM
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

Tags
PanelBar
Asked by
mlandauer
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
mlandauer
Top achievements
Rank 1
kd345205
Top achievements
Rank 1
Share this question
or