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

How to Validate RadFileUpload which is inside Radgrid ?

3 Answers 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ashok kumar
Top achievements
Rank 1
ashok kumar asked on 18 Mar 2010, 07:46 PM
Hello ,

i would like to know how to validate RadFileUpload which is inside the FormTemplate of EditFormSettings in rad grid .

i wonder if this could be possible and i was not able to find any similar post of my kind of issue.

i would like to know the client side validation and server side validation of it .

i have pasted the code which am using right now ,  you can see for the control ID -  RUPhoto

please advise your ideas.

<telerik:RadGrid ID="RadGridHodesTeam" runat="server" GridLines="None" AllowPaging="true" 
                    EnableEmbeddedSkins="false" PageSize="4" OnNeedDataSource="RadGridHodesTeam_NeedDataSource" 
                    Skin="Office2007" OnPreRender="RadGridHodesTeam_PreRender" OnInsertCommand="RadGridHodesTeam_InsertCommand"
                    <PagerStyle Mode="NextPrevAndNumeric" /> 
                    <MasterTableView TableLayout="Auto" DataKeyNames="ID,Name,Title,OfficePhone,Extension,SecondPhone,Extension1,Fax,Email" 
                        CommandItemDisplay="TopAndBottom" ShowHeader="false"
                        <ItemTemplate> 
                            <%# (((GridItem)Container).ItemIndex != 0)? "</td></tr></table>" : "" %> 
                            <asp:Panel ID="ItemContainer" CssClass='<%# (((GridItem)Container).ItemType == GridItemType.Item)? "item" : "alternatingItem" %>' 
                                runat="server" Height="200px"
                                <div class="itempadding"
                                    <table> 
                                        <tr visible="false" style="display: none;"
                                            <td> 
                                                <b>Id:</b></td
                                            <td> 
                                                <%#Eval("ID")%> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                <b>Name:</b></td
                                            <td> 
                                                <%#Eval("Name")%> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                <b>Title:</b></td
                                            <td> 
                                                <%# Eval("Title")%> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                <b>Phone:</b></td
                                            <td> 
                                                <%# Eval("OfficePhone")%> 
                                            </td> 
                                        </tr> 
                                        <tr visible="false" style="display: none;"
                                            <td> 
                                                <b>Extension:</b></td
                                            <td> 
                                                <%# Eval("Extension")%> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                <b>Mobile:</b></td
                                            <td> 
                                                <%# Eval("SecondPhone")%> 
                                            </td> 
                                        </tr> 
                                        <tr visible="false" style="display: none;"
                                            <td> 
                                                <b>Extension:</b></td
                                            <td> 
                                                <%# Eval("Extension1")%> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                <b>Fax:</b></td
                                            <td> 
                                                <%# Eval("Fax")%> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                <b>EMail:</b></td
                                            <td> 
                                                <%# Eval("Email")%> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                    <table id="Table1" style="height: 25px; display: block;" runat="server"
                                        <tr id="trBtns"
                                            <td align="center"
                                                <href="#" onclick="openRadWindow('<%#DataBinder.Eval(Container.DataItem,"ID")%>');return false;"
                                                    Edit </a> 
                                            </td> 
                                            <td align="center"
                                                <href="#" onclick="openRadWindow1('<%#DataBinder.Eval(Container.DataItem,"ID")%>');return false;"
                                                    Delete </a> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </div> 
                            </asp:Panel> 
                        </ItemTemplate> 
                        <EditFormSettings EditFormType="Template"
                            <FormTemplate> 
                                <div style="width: 100%"
                                    <table align="center"
                                        <tr> 
                                            <td> 
                                                Name: 
                                            </td> 
                                            <td> 
                                                <telerik:RadTextBox ID="RadtxtName" runat="server"
                                                </telerik:RadTextBox> 
                                                <asp:RequiredFieldValidator ID="rfvtxtName" ControlToValidate="RadtxtName" runat="server" 
                                                    Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator></td
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Title: 
                                            </td> 
                                            <td> 
                                                <telerik:RadTextBox ID="RadTxtTitle" runat="server"
                                                </telerik:RadTextBox> 
                                                <asp:RequiredFieldValidator ID="rfvRadTxtTitle" ControlToValidate="RadTxtTitle" runat="server" 
                                                    Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator></td
                                        </tr> 
                                        <tr style="width: 200px;"
                                            <td> 
                                                Phone: 
                                            </td> 
                                            <td class="recordsfields"
                                                <telerik:RadTextBox ID="RadTxtOfficePhone" runat="server"
                                                </telerik:RadTextBox> 
                                                <asp:RequiredFieldValidator ID="rfvRadTxtOfficePhone" CssClass="padding10px" ControlToValidate="RadTxtOfficePhone" 
                                                    runat="server" Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator> 
                                                <asp:RegularExpressionValidator ID="revRadTxtOfficePhone" runat="server" ErrorMessage="Number Is Not Valid!!" 
                                                    Display="Dynamic" CssClass="padding10px" ControlToValidate="RadTxtOfficePhone" 
                                                    ValidationExpression="^[0-9-+]*$"></asp:RegularExpressionValidator></td
                                        </tr> 
                                        <tr visible="false" style="display: none;"
                                            <td> 
                                                Extension: 
                                            </td> 
                                            <td> 
                                                <telerik:RadTextBox ID="RadTxtOfficeExt" runat="server"
                                                </telerik:RadTextBox> 
                                                <asp:RegularExpressionValidator ID="revRadTxtOfficeExt" runat="server" ErrorMessage="Number Only !!" 
                                                    ControlToValidate="RadTxtOfficeExt" ValidationExpression="^\d+$"></asp:RegularExpressionValidator> 
                                                <%--<asp:RequiredFieldValidator ID="rfvRadTxtOfficeExt" ControlToValidate="RadTxtOfficeExt" 
                                                        runat="server" Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>--%> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Mobile: 
                                            </td> 
                                            <td class="recordsfields"
                                                <telerik:RadTextBox ID="RadTxtSecondPhone" runat="server"
                                                </telerik:RadTextBox> 
                                                <%--<asp:RequiredFieldValidator ID="rfvRadTxtSecondPhone" ControlToValidate="RadTxtSecondPhone" 
                                                        runat="server" Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>--%> 
                                                <asp:RegularExpressionValidator ID="revRadTxtSecondPhone" runat="server" ErrorMessage="Number Is Not Valid !!" 
                                                    CssClass="padding10px" ControlToValidate="RadTxtSecondPhone" ValidationExpression="^[0-9-+]*$"></asp:RegularExpressionValidator></td
                                        </tr> 
                                        <tr visible="false" style="display: none;"
                                            <td> 
                                                Extension: 
                                            </td> 
                                            <td> 
                                                <telerik:RadTextBox ID="RadTxtSecondExtension" runat="server"
                                                </telerik:RadTextBox> 
                                                <asp:RegularExpressionValidator ID="revRadTxtSecondExtension" runat="server" ErrorMessage=" Number Only !!" 
                                                    ControlToValidate="RadTxtSecondExtension" ValidationExpression="^\d+$"></asp:RegularExpressionValidator> 
                                                <%--<asp:RequiredFieldValidator ID="rfvRadTxtExtension" ControlToValidate="RadTxtSecondExtension" 
                                                        runat="server" Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>--%> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Fax: 
                                            </td> 
                                            <td> 
                                                <telerik:RadTextBox ID="RadTxtFax" runat="server"
                                                </telerik:RadTextBox> 
                                                <%--<asp:RequiredFieldValidator ID="rfvRadTxtFax" ControlToValidate="RadTxtFax" runat="server" 
                                                    Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>--%> 
                                                <asp:RegularExpressionValidator ID="revRadTxtFax" runat="server" ErrorMessage="Invalid Format" 
                                                    Display="Dynamic" ControlToValidate="RadTxtFax" ValidationExpression="^[0-9-+]*$"></asp:RegularExpressionValidator> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                EMail: 
                                            </td> 
                                            <td> 
                                                <telerik:RadTextBox ID="RadTxtEmail" runat="server"
                                                </telerik:RadTextBox> 
                                                <asp:RequiredFieldValidator ID="rfvRadTxtEmail" ControlToValidate="RadTxtEmail" runat="server" 
                                                    Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator> 
                                                <asp:RegularExpressionValidator ID="revRadTxtEmail" runat="server" ErrorMessage="Email Not Valid!" 
                                                    Display="Dynamic" ControlToValidate="RadTxtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Photo: 
                                            </td> 
                                            <td> 
                                                <telerik:RadUpload ID="RUPhoto" runat="server" ControlObjectsVisibility="None" AllowedFileExtensions=".jpg,.jpeg" 
                                                    Skin="Office2007"
                                                </telerik:RadUpload> 
                                                <br /> 
                                                <%--<asp:Label ID="lblerr" runat="server" Text="Invalid File" Visible="false" ></asp:Label>--%> 
                                                Image size should be 145 x 55 px 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Team Member URL: 
                                            </td> 
                                            <td> 
                                                <telerik:RadTextBox ID="RadTxtTeamMember" runat="server"
                                                </telerik:RadTextBox> 
                                                <asp:RegularExpressionValidator ID="RevRadTxtTeamMember" runat="server" ErrorMessage="URL Invalid" 
                                                    ControlToValidate="RadTxtTeamMember" ValidationExpression="^(ht|f)tp(s?)\:\/\/(([a-zA-Z0-9\-\._]+(\.[a-zA-Z0-9\-\._]+)+)|localhost)(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?([\d\w\.\/\%\+\-\=\&amp;\?\:\\\&quot;\'\,\|\~\;]*)$"
                                                </asp:RegularExpressionValidator> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                            </td> 
                                            <td> 
                                                <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' 
                                                    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                                </asp:Button> 
                                                <asp:Button ID="BtnCancel" runat="server" Text="Cancel" CausesValidation="false" 
                                                    CommandName="Cancel" /></td
                                        </tr> 
                                    </table> 
                                </div> 
                            </FormTemplate> 
                        </EditFormSettings> 
                    </MasterTableView> 
                    <GroupingSettings CaseSensitive="false" /> 
                </telerik:RadGrid> 


Thanks in Advance ,

Ashok.C

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Mar 2010, 08:10 AM
Hi,

Please have a look at the validation mechanisms shown in the links below.Hope you find these links useful.

Grid / Flexible Server-side Validation
Validation
Perform validation over the file input

Princy
0
ashok kumar
Top achievements
Rank 1
answered on 19 Mar 2010, 07:17 PM

Princy :

can you show me some live sample .

Regards,

Ashok
0
Princy
Top achievements
Rank 2
answered on 22 Mar 2010, 06:42 AM
Hi,

Here is an example of how this can be achieved:

ASPX:
            <EditFormSettings EditFormType="Template"
                <FormTemplate> 
                    <telerik:RadUpload AllowedFileExtensions=".jpg" ID="RadUpload1" runat="server"
                    </telerik:RadUpload> 
                    <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validateRadUpload" 
                        Display="Dynamic" ErrorMessage=" Please select file to be uploaded"></asp:CustomValidator> 
                    <asp:Button ID="Button1" runat="server" Text="Update" /> 
                </FormTemplate> 
            </EditFormSettings> 

JS:
 <script type="text/javascript" language="javascript"
        function validateRadUpload(source, e) { 
            e.IsValid = false
            var upload = $find(source.parentNode.getElementsByTagName('div')[0].id); 
            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
                } 
            } 
        } 
    </script> 


Princy
Tags
Grid
Asked by
ashok kumar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
ashok kumar
Top achievements
Rank 1
Share this question
or