OnClientClicking & RequiredFieldValidator problems

2 posts, 1 answers
  1. Kurt Kluth
    Kurt Kluth avatar
    144 posts
    Member since:
    Oct 2009

    Posted 08 Oct 2014 Link to this post

    I have looked at the following forum post: http://www.telerik.com/forums/strange-behavior-when-using-args-set-cancel-true and although my code is similar still having odd behavior. 

    When clicking on the radButton it will fire the validation but it takes clicking on the "OK" button twice before the validation summary disappears.

    Suggestions?

    <telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            function ShowConfirm(clickedButton, args) {
                var validated = Page_ClientValidate('Form');
                if (validated) {
                    args.set_cancel(true);
                    function callBackFunction(arg) {
                        if (arg == true) {
                            clickedButton.click();
                        }
                    }
                    //Open the window
                    $find("<%=confirmWindow.ClientID %>").show();
                    //Focus the Yes button
                    $find("<%=btnYes.ClientID %>").focus();
                    //Cancel the postback
                    args.set_cancel(true);
                }
            }
     
            function YesOrNoClicked(sender, args) {
                var oWnd = $find("<%=confirmWindow.ClientID %>");
                oWnd.close();
                if (sender.get_text() == "Yes") {
                    $find("<%=_btnFinish.ClientID %>").click();
                }
            }
        </script>
    </telerik:RadCodeBlock>

        <asp:Panel runat="server" ID="ShowHistorical" Visible="false">
        <tr>
            <td style="text-align: center;" align="center">There is no <strong>Historical data for <asp:Label ID="_Step2CUName" runat="server"></asp:Label>.</strong>  Please select this credit unions Member Type before proceeding.<br />
                <br />
                <telerik:RadDropDownList ID="_ddMember" runat="server" AutoPostBack="true" DefaultMessage="Select Member Type"></telerik:RadDropDownList>  
                <asp:RequiredFieldValidator ID="_reqValMemberType" runat="server" ControlToValidate="_ddMember" Text="*" ForeColor="Red"
                    ErrorMessage="You must select a Member Type before you can submit this Credit Union to be reinstated!<br />"
                    ValidationGroup="Form" Display="Dynamic" EnableClientScript="true"></asp:RequiredFieldValidator>
            </td>
        </tr>
        </asp:Panel>
        <tr>
            <td align="center">
                <telerik:RadButton ID="_btnFinish" runat="server" Text="Finish" CommandName="Continue" ValidationGroup="Form"  Visible="false"
                    OnClientClicking="ShowConfirm"></telerik:RadButton>
                <asp:ValidationSummary ID="ValidationSummary2" runat="server" ValidationGroup="Form" ShowMessageBox="true" ShowSummary="false"  DisplayMode="BulletList" />
            </td>
        </tr>
    </table>

    <telerik:RadWindowManager ID="windowManager1" runat="server">
    </telerik:RadWindowManager>
    <telerik:RadWindow ID="confirmWindow" runat="server" VisibleTitlebar="false" VisibleStatusbar="false"
        Modal="true" Behaviors="None" Height="200px" Width="350px">
        <ContentTemplate>
            <div style="margin-top: 30px; float: left;">
                    <div style="width: 60px; padding-left: 15px; float: left;">
                        <img src="/images/ModalDialogAlert.gif" alt="Confirm Page" />
                    </div>
                    <div style="width: 230px; float: left;">
                        <asp:Label ID="lblConfirm" Font-Size="14px" Text=""
                            runat="server"></asp:Label>
                        <br />
                        <br />
                        <telerik:RadButton ID="btnYes" runat="server" Text="Yes" AutoPostBack="false" OnClientClicked="YesOrNoClicked">
                            <Icon PrimaryIconCssClass="rbOk"></Icon>
                        </telerik:RadButton>
                        <telerik:RadButton ID="btnNo" runat="server" Text="No" AutoPostBack="false" OnClientClicked="YesOrNoClicked">
                            <Icon PrimaryIconCssClass="rbCancel"></Icon>
                        </telerik:RadButton>
                    </div>
            </div>
        </ContentTemplate>
    </telerik:RadWindow>







  2. Answer
    Danail Vasilev
    Admin
    Danail Vasilev avatar
    1494 posts

    Posted 13 Oct 2014 Link to this post

    Hello Kurt,

    The Page_ClientValidate method validates the page once again when the button is clicked and that is why the validation summary popup shows twice. I can suggest that you place the logic that you want to be executed only when the validation passes and prior to the postback in the OnClientClicked event. The rest of the logic that you want to be executed every time the button is clicked can be placed in the OnClientClicking event.

    Regards,
    Danail Vasilev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top