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

Radconfirm fired after validation?

6 Answers 154 Views
Window
This is a migrated thread and some comments may be shown as answers.
T. Stanley
Top achievements
Rank 1
T. Stanley asked on 05 Dec 2009, 03:23 PM
Hi.  I would like to use a built-in radconfirm window to add the "Are you sure?" step to a user's input, but I would like for this to occur after the validators used on the page have fired and functioned.  That way the page's logic has insured that the data is correct before it asks "Are you sure?"  Every way that I try to open the radconfirm dialog, it opens first, ahead of the validation.  How can I correct this?

Thanks so much for any help!

6 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 07 Dec 2009, 12:15 PM
Hi T. Stanley,

I would suggest to use the approach shown below:

 

<%@ Page Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager" runat="server">
    </asp:ScriptManager>
    <asp:TextBox ID="TextBox1" runat="server" />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1"
        ErrorMessage="Card Number. " Display="Static" Width="100%" runat="server">
                             
    </asp:RequiredFieldValidator>
    <asp:ValidationSummary ID="valSummary" DisplayMode="BulletList" runat="server" HeaderText="You must enter a value in the following fields:"
        Font-Names="verdana" Font-Size="12" />
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    </telerik:RadWindowManager>
    <asp:Button ID="Button1" Text="SubmitConfirm" runat="server" OnClientClick="ShowConfirm(this); return false; " />
 
    <script type="text/javascript">
        function ShowConfirm(clickedButton)
        {
            var reqFiewldVal = document.getElementById("RequiredFieldValidator1");
            // Validate the text box ;
            ValidatorValidate(reqFiewldVal);
 
            if (reqFiewldVal.isvalid)
            {
 
                function callBackFn(arg)
                {
                    if (arg == true)
                    {
                        __doPostBack(clickedButton.name, "");
                    }
                }
 
                radconfirm("Are you sure?", callBackFn, 400, 200, null, "Title");
            }
        }
    </script>
    </form>
</body>
</html>


Greetings,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Steve Napurano
Top achievements
Rank 1
answered on 28 Aug 2011, 08:19 AM
HI, I am trying this with a RAdButton.

I tried OnClientClicking and OnClientClick...no luck.

Any ideas? Thanks!!!

function

 

ShowConfirm(clickedButton) {

 

 

var reqFiewldVal = document.getElementById("reqClubName");

 

ValidatorValidate(reqFiewldVal);

 

if (reqFiewldVal.isvalid) {

 

 

function callBackFn(arg) {

 

 

if (arg == true) {

 

__doPostBack(clickedButton.name,

"");

 

}

}

 

var text = "Are you sure you want to create this new Club?";

 

radconfirm(text, callBackFunction, 350, 100,

null, "Add New Club");

 

}

}


<

 

asp:RequiredFieldValidator ValidationGroup="grpClub" runat="server" ErrorMessage="Club/Activity Name is required" ID="reqClubName" ControlToValidate="txtClubName" Display="None"></asp:RequiredFieldValidator>

<

 

telerik:RadButton Font-Size="12" ID="btnUpload" runat="server" Text="Upload" Skin="Black" CausesValidation="true" ValidationGroup="grpClub" OnClientClicking="ShowConfirm(this); return false; ">

 

 

<Icon PrimaryIconCssClass="rbUpload" PrimaryIconLeft="4" PrimaryIconTop="4"/>

 

 

</telerik:RadButton>

 

0
Marin Bratanov
Telerik team
answered on 30 Aug 2011, 09:48 AM
Hello Steve,

There are several issue with the provided code:
1) the handler for the RadButton is attached by passing just the function name as an argument, not like for the regular asp button
2) to cancel the postback you need to call its args.set_cancel(true) command, not return false;
3) to perform the postback you could call a programmatic click on the RadButton via its click() method
4) the name of the callback function is not correct (it does not match the one declared in the radconfirm call)

Here follows the code that works correctly on my end:
function ShowConfirm(clickedButton, args)
{
    args.set_cancel(true);
    var reqFiewldVal = document.getElementById("reqClubName");
    ValidatorValidate(reqFiewldVal);
    if (reqFiewldVal.isvalid)
    {
        function callBackFunction(arg)
        {
            if (arg == true)
            {
                clickedButton.click();
            }
        }
        var text = "Are you sure you want to create this new Club?";
        radconfirm(text, callBackFunction, 350, 100, null, "Add New Club");
    }
}

and the markup:
<asp:TextBox ID="txtClubName" runat="server" />
<asp:RequiredFieldValidator ValidationGroup="grpClub" runat="server" ErrorMessage="Club/Activity
Name is required" ID="reqClubName" ControlToValidate="txtClubName" Display="None"></asp:RequiredFieldValidator>
<telerik:RadButton Font-Size="12" ID="btnUpload" runat="server" Text="Upload" Skin="Black"
    CausesValidation="true" ValidationGroup="grpClub" OnClientClicking="ShowConfirm">
    <Icon PrimaryIconCssClass="rbUpload" PrimaryIconLeft="4" PrimaryIconTop="4" />
</telerik:RadButton>
<telerik:RadWindowManager runat="server" ID="RadWindowManager1"></telerik:RadWindowManager>


An example of a confirmation used with a RadButton is available in the following online demo: http://demos.telerik.com/aspnet-ajax/button/examples/confirm/defaultcs.aspx.

I hope the information above will help you successfully implement the desired functionality.

On a side note - I would advise providing some information to the user why the validation failed and the button seems to be non-functional.


Kind regards,
Marin
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Steve Napurano
Top achievements
Rank 1
answered on 30 Aug 2011, 07:21 PM
HI and Thanks!!!

Shouldnt the validator show the err msg if it is not valid?
What I did was I put a radconfirm in the 'else' statement of IsValid().
Whats funny is that AFTER the radwindow shows, the validator says 'Club name required' as it should but when I remove the radconfirm from the else...it doesnt show.

What should I do in the else statement to make the validator show the error (i dont want to show a radconfirm in this case, it was just a test to see what happened)

Thanks so much for the help, greatly appreciated!!!!

if

 

(reqFiewldVal.isvalid) {

 

 

function callBackFunction(arg) {

 

 

if (arg == true) {

 

clickedButton.click();

}

}

 

var text = "Are you sure you want to create this new Club?";

 

radconfirm(text, callBackFunction, 350, 100,

null, "Add New Club");

 

}

 

else

 

{

var text = "Please enter Club name.";

 

radconfirm(text, callBackFunction, 350, 100,

null, "Add New Club");

 

 

 

 

}

0
Accepted
Marin Bratanov
Telerik team
answered on 01 Sep 2011, 11:06 AM
Hello Steve,

I would recommend that you start by examining this help article: http://www.telerik.com/help/aspnet-ajax/radbutton-validation-with-postback-confirm.html.

Note the Display=None property of your RequiredFiedValidator - this is the main reason why you generally have no error message.

Also, if I have understood your scenario correctly the radconfirm should appear only if the validation is successful and it should confirm if the user really wants to submit the page. He/she would not be able to submit it if the validation did not pass, therefore the if() statement (where the confirm is called) should be entered only if the validation passed.

That being said I attached the modified page that exhibits the described behavior: http://screencast.com/t/RUAurZtRPrxf. I hope it helps you implement the desired functionality. Note that I have placed the RequiredFieldValidator after the RadButton, as otherwise the change of display of the error message will move the RadButton and will cause issues with the user clicking.

On a side note - the CausesValidation property of the RadButton is not necessary - it defaults to true and besides, the ValidationGroup is set.


Kind regards,
Marin
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Steve Napurano
Top achievements
Rank 1
answered on 08 Sep 2011, 03:47 AM
Thank you so much!
Tags
Window
Asked by
T. Stanley
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Steve Napurano
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or