add two types of validation check to radbutton

Thread is closed for posting
4 posts, 1 answers
  1. Chap
    Chap avatar
    18 posts
    Member since:
    Oct 2012

    Posted 24 Oct 2012 Link to this post

    Hello,
    I have a two radtextbox, rad upload , radbutton and a seperate rad grid.
    I already added validation to radtextboxes and rad upload using asp req field validator and custom field validator.
    And I also wanted to add another validation to rad upload button which checks the value in radtextbox1 if exists in the radgrid column "TemplateName". if this condition get true I want a popup message "This tmp exist, are you want to replace it?" if user click ok. it will call the method and if not do nothing. Otherwise do normal scenario. Can I do this? if can, how?

    Here is the code snippts,

    <div style="margin-left: 12px;">
                    <table>
                    <tr>
                    <td></td>
                    </tr>
                        <tr>
                            <td>
                                <telerik:RadTextBox ID="RadTextBox1" runat="server" EnableSingleInputRendering="true"
                                    EmptyMessage="Template Name..." Width="230px">
                                </telerik:RadTextBox>
                            </td>
                            <td>
                                <asp:RequiredFieldValidator ID="TextBoxRequiredFieldValidator" runat="server" Display="Dynamic"
                                    ControlToValidate="RadTextBox1" ErrorMessage="*Please enter a name" ForeColor="DimGray"
                                    CssClass="fontFamily" ValidationGroup="SubmitButton"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td style="height: 64px">
                                <telerik:RadTextBox ID="RadTextBox2" runat="server" EnableSingleInputRendering="true"
                                    EmptyMessage="Template Description..." TextMode="MultiLine" Width="230px" Height="60px">
                                </telerik:RadTextBox>
                            </td>
                            <td style="height: 64px">
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
                                    ControlToValidate="RadTextBox2" ErrorMessage="*Please enter a description" ForeColor="DimGray"
                                    CssClass="fontFamily" ValidationGroup="SubmitButton">
                                </asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <telerik:RadUpload ID="RadUpload1" runat="server" AllowedFileExtensions=".doc,.docx"
                                    ControlObjectsVisibility="None" MaxFileInputsCount="1" OverwriteExistingFiles="true"
                                    ValidationGroup="SubmitButton" Width="240px">
                                </telerik:RadUpload>
                                <%-- <asp:Button ID="SubmitButton" runat="server" CssClass="fontFamily"
                                        OnClick="SubmitButton_Click" Text="Upload" ValidationGroup="SubmitButton"
                                        Width="16%" />--%>
                            </td>
                            <td>
                                <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validateRadUpload"
                                    CssClass="fontFamily" ErrorMessage="*Please select a ms word template file" ForeColor="DimGray"
                                    ValidationGroup="SubmitButton"></asp:CustomValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <telerik:RadButton ID="SubmitButtdon" runat="server" Text="Upload" OnClick="SubmitButton_Click"
                                    ValidationGroup="SubmitButton" Width="30%" OnClientClicked="checkExt">
                                </telerik:RadButton>
                            </td>
                        </tr>
                    </table>
                    <table>
                        <tr>
                            <td>
                                <telerik:RadProgressArea ID="RadProgressArea1" runat="server"  >
                                    </telerik:RadProgressArea>
                            </td>
                        </tr>
                    </table>
                </div>

    Javascript using

    function validateRadUpload(source, e) {
                e.IsValid = false;
                var upload = $find("<%= RadUpload1.ClientID %>");
                var inputs = upload.getFileInputs();
                for (var i = 0; i < inputs.length; i++) {
                    //check for empty string or invalid extension    
                    if (inputs[i].value != "" && upload.isExtensionValid(inputs[i].value)) {
                        e.IsValid = true;
                        break;
                    }
                }
            }

    this is the grid

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" CellSpacing="0"
                                GridLines="None" OnItemCommand="RadGrid1_ItemCommand" Width="100%" OnNeedDataSource="RadGrid1_NeedDataSource">
                                <FilterMenu EnableImageSprites="False">
                                </FilterMenu>
                                <MasterTableView>
                                    <Columns>
                                        <telerik:GridButtonColumn ButtonType="LinkButton" Text="<img src='../App_Themes/default/images/Delete.gif' border='0' title='Delete'/>"
                                            UniqueName="DeleteColumn" ConfirmText="Are you sure you want to delete this Template?"
                                            ConfirmTitle="Delete Template" CommandName="Delete">
                                            <HeaderStyle Width="3%" />
                                        </telerik:GridButtonColumn>
                                        <telerik:GridTemplateColumn HeaderText="" UniqueName="Image">
                                            <ItemTemplate>
                                                <asp:ImageButton ID="GD" runat="server" ImageUrl="~/App_Themes/Default/images/Printer16.gif"
                                                    CommandName="G" OnClick="ImageButton1_Click" ToolTip="Generate Documents"></asp:ImageButton>
                                            </ItemTemplate>
                                            <HeaderStyle Width="3%" />
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText="" UniqueName="Image">
                                            <ItemTemplate>
                                                <asp:ImageButton ID="DT" runat="server" ImageUrl="~/App_Themes/Default/images/genDoc.gif"
                                                    CommandName="DT" OnClick="ImageButton2_Click" ToolTip="Download Template"></asp:ImageButton>
                                            </ItemTemplate>
                                            <HeaderStyle Width="3%" />
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridBoundColumn FilterControlAltText="Filter column column" HeaderText="Template Name"
                                            UniqueName="TemplateName" DataField="TemplateName">
                                            <HeaderStyle Width="30%" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn FilterControlAltText="Filter column column" HeaderText="Template Details"
                                            UniqueName="TemplateDescript" DataField="TemplateDescript">
                                            <HeaderStyle Width="61%" />
                                        </telerik:GridBoundColumn>
                                    </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>

    This grid is enable ajax to call server function

    <script type="text/javascript">
        function requestStart(sender, args) {
            if (args.get_eventTarget().indexOf("GD") > 0)
                args.set_enableAjax(false);
            if (args.get_eventTarget().indexOf("DT") > 0)
                args.set_enableAjax(false);
        }
    </script>

    Please help me, Thanks
  2. Chap
    Chap avatar
    18 posts
    Member since:
    Oct 2012

    Posted 25 Oct 2012 Link to this post

    I did upto some level using this function, nw it checks my condition and give confirm box, but when I click ok, it does not doing nothing, 
    please tel me the wrong

    function checkExt(sender, args) {
                var grid = $find("<%=RadGrid1.ClientID %>");
                var MasterTable = grid.get_masterTableView();
                var numberOfRows = MasterTable.get_dataItems().length;
                var rb = $find("<%= RadTextBox1.ClientID %>");
                var textBoxVal = rb.get_value();


                for (var i = 0; i < numberOfRows; i++) {
                    var Row = MasterTable.get_dataItems()[i];
                    var cell = MasterTable.getCellByColumnUniqueName(Row, "TemplateName");
                    var onlyTmpName = cell.innerHTML.split(".");
                    if (textBoxVal.toLowerCase() == onlyTmpName[0].toLowerCase()) {
                        args.set_cancel(!window.confirm("Are you sure you want to overwrite this template?"));
                    }
                }
            } 
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 29 Oct 2012 Link to this post

    Hi Chap,

     
    I have tested the following code and it worked as expected at my side:

    <script type="text/javascript">
                function OnClientClicking(sender, args) {
                    args.set_cancel(!window.confirm("Are you sure you want to overwrite this template?"));
                }
     
            </script>
           <telerik:RadUpload ID="RadUpload1" runat="server" AllowedFileExtensions=".doc,.docx"
                                    ControlObjectsVisibility="None" MaxFileInputsCount="1" OverwriteExistingFiles="true"
                                    ValidationGroup="SubmitButton" Width="240px">
                                </telerik:RadUpload>
             <telerik:RadProgressArea ID="RadProgressArea1" runat="server"  >
                                    </telerik:RadProgressArea>
                     <telerik:RadProgressManager ID="RadProgressManager1" runat="server" />
            <telerik:RadButton runat="server" ID="RB1" OnClientClicking="OnClientClicking">
     
            </telerik:RadButton>

    Please review it and let me know what else should I add to this code in order to reproduce the unusual behavior you are experiencing.

    Greetings,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  5. Chap
    Chap avatar
    18 posts
    Member since:
    Oct 2012

    Posted 30 Oct 2012 Link to this post

    thanks, it works well with this OnClientClicking="OnClientClicking"
Back to Top