wierd error with RadUpload custom validation

Thread is closed for posting
9 posts, 0 answers
  1. MBEN
    MBEN avatar
    159 posts
    Member since:
    Nov 2011

    Posted 16 Nov 2011 Link to this post

    Hi,

    I was working with RadUpload inside the grid as shown in
    http://demos.telerik.com/aspnet-ajax/controls/examples/integration/raduploadinajaxifiedgrid/defaultcs.aspx?product=upload

    I have 2 other dropdown controls in my form template. The dropdowns are cascading.
    I need to first select something in the dropdown and then select the file to be uploaded.
    For this I disable the Radupload and second dropdown on page load and enable them when something has been selected in the first dropdown.  The selection in the second dropdown does not affect the Radupload.
    However I am having issue with the custom validator attached to the RadUpload. Once I select from my first dropdown i immediately get an error for selecting a file. I tried to remove the custom validator but that gives me an 'undefined' error.
    If I use the function as it is my dropdown and upload control does not get enabled.

    Please help.
  2. MBEN
    MBEN avatar
    159 posts
    Member since:
    Nov 2011

    Posted 17 Nov 2011 Link to this post

    I was able to get rid of the 'undefined' error.
    That was because I was updating the second combo box in the AJAXSettings.

    But I still cannot get the second combo box to load without getting the validation error on radupload.

    Below is my aspx code
    <%@ Page Language="c#" Inherits="DSys.administration.participantDocumentManagement"
        CodeFile="participantDocumentManagement.aspx.cs" MasterPageFile="~/site.master" %>
      
    <%@ MasterType VirtualPath="~/site.master" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
        </asp:ScriptManagerProxy>
        <telerik:RadAjaxManagerProxy ID="RadAJAXManagerProxy1" runat="server">
            <%--<AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadComboPlan">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadComboParticipant" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>--%>
        </telerik:RadAjaxManagerProxy>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
      
            <script type="text/javascript">
                var uploadedFilesCount = 0;
                var isEditMode;
      
                //On insert and update buttons click temporarily disables ajax to perform upload actions
                function conditionalPostback(sender, eventArgs) {
                    var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
                    if (eventArgs.get_eventTarget().match(theRegexp)) {
                        var upload = $find(window['UploadId']);
      
                        //AJAX is disabled only if file is selected for upload
                        if (upload.getFileInputs()[0].value != "") {
                            eventArgs.set_enableAjax(false);
                        }
                    }
                }
                              
                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;
                            }
                        }
                }
      
                function gridCreated(sender, args) { window.gridControl = sender; }   
                          
            </script>
      
        </telerik:RadCodeBlock>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr valign="top">
                <td colspan="3">
                    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="conditionalPostback">
                        <telerik:RadProgressManager ID="RadProgressManager1" runat="server" />
                        <telerik:RadProgressArea ID="RadProgressArea1" runat="server" />
                        <telerik:RadGrid ID="rgDocumentManagement" runat="server" GridLines="Vertical" AllowPaging="true"
                            AutoGenerateColumns="False" EnableLinqExpressions="false" AllowSorting="true"
                            OnItemCreated="rgDocumentManagement_ItemCreated" DataSourceID="_dataSrcDocuments"
                            OnItemCommand="rgDocumentManagement_ItemCommand" AllowFilteringByColumn="false"
                            AllowCustomPaging="false" Width="99%" OnItemDataBound="rgDocumentManagement_ItemDataBound"
                            OnDeleteCommand="rgDocumentManagement_DeleteCommand" OnCancelCommand="rgDocumentManagement_CancelCommand"
                            PageSize="25">
                            <MasterTableView TableLayout="Fixed" HierarchyDefaultExpanded="true" ClientDataKeyNames="DocumentID"
                                CommandItemDisplay="Top" DataKeyNames="DocumentID">
                                <Columns>
                                    <telerik:GridBoundColumn DataField="DocumentID" UniqueName="DocumentID" Visible="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="DocumentName" UniqueName="DocumentName" HeaderText="Document Name">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="DatePosted" UniqueName="DatePosted" HeaderText="Posted On">
                                    </telerik:GridBoundColumn>
                                                                   <telerik:GridBoundColumn DataField="PlanID" UniqueName="PlanID" HeaderText="PlanID"
                                        Visible="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="PlanName" UniqueName="PlanName" HeaderText="Plan">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="ParticipantID" UniqueName="ParticipantID" HeaderText="ParticipantID"
                                        Visible="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="ParticipantName" UniqueName="ParticipantName"
                                        HeaderText="Participant">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton">
                                        <HeaderStyle Width="2%" />
                                    </telerik:GridButtonColumn>
                                </Columns>
                                <EditFormSettings EditFormType="Template">
                                    <EditColumn UniqueName="EditCommandColumn">
                                    </EditColumn>
                                    <FormTemplate>
                                        <table>
                                             <tr>
                                                <td>
                                                    <asp:Label ID="Label2" runat="server" Text="Plan:"></asp:Label>
                                                </td>
                                                <td>
                                                    <telerik:RadComboBox ID="RadComboPlan" runat="server" DataSourceID="_dataSrcPlans"
                                                        AutoPostBack="true" OnSelectedIndexChanged="RadComboPlan_SelectedIndexChanged"
                                                        DataTextField="PlanName" DataValueField="PlanID" Width="250px" AppendDataBoundItems="true">
                                                        <Items>
                                                            <telerik:RadComboBoxItem Text=" " Value="0" Selected="true" />
                                                        </Items>
                                                    </telerik:RadComboBox>
                                                    <asp:RequiredFieldValidator ID="rfvPlan" runat="server" ControlToValidate="RadComboPlan"
                                                        ErrorMessage="Please select a Plan" Display="Dynamic" SetFocusOnError="true" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="Label3" runat="server" Text="Participant:"></asp:Label>
                                                </td>
                                                <td>
                                                    <telerik:RadComboBox ID="RadComboParticipant" runat="server" Width="250px" DataSourceID="_dataSrcParticipants"
                                                        DataTextField="FullName" DataValueField="ParticipantID" Enabled="true">
                                                        <Items>
                                                            <telerik:RadComboBoxItem Text=" " Value="0" Selected="true" />
                                                        </Items>
                                                    </telerik:RadComboBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="Label4" runat="server" Text="Browse:"></asp:Label>
                                                </td>
                                                <td>
                                                    <telerik:RadUpload runat="server" ID="RadUpload" AllowedFileExtensions="pdf,txt,xls"
                                                        MaxFileSize="1048576" ControlObjectsVisibility="None" 
                                                        MaxFileInputsCount="1" InitialFileInputsCount="1" Enabled="true">
                                                    </telerik:RadUpload>
                                                    <asp:CustomValidator ID="cvUploadDocument" runat="server" ErrorMessage="Please select file to be uploaded"
                                                        ClientValidationFunction="validateRadUpload" Display="Dynamic"></asp:CustomValidator>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" style="text-align: center">
                                                    <asp:Button ID="btnAdd" Text="Add" runat="server" CommandName="Insert" />
                                                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false" />
                                                </td>
                                            </tr>
                                        </table>
                                    </FormTemplate>
                                </EditFormSettings>
                            </MasterTableView>
                            <ClientSettings>
                                <ClientEvents OnGridCreated="gridCreated" />
                            </ClientSettings>
                        </telerik:RadGrid>
                    </telerik:RadAjaxPanel>
                </td>
            </tr>
              </table>
        <asp:ObjectDataSource ID="_dataSrcDocuments" runat="server" SelectMethod="ListDocumentsByClient"
            TypeName="DBLib.Documents">
            <SelectParameters>
                <asp:ProfileParameter Name="ClientID" PropertyName="ClientID" DefaultValue="-1" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:ObjectDataSource ID="_dataSrcPlans" runat="server" SelectMethod="ListWebEnabledByClient"
            TypeName="DBLib.Plan">
            <SelectParameters>
                <asp:ProfileParameter Name="ClientID" PropertyName="ClientID" DefaultValue="-1" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:ObjectDataSource ID="_dataSrcParticipants" runat="server" SelectMethod="ListByClientAndPlan"
            TypeName="DBLib.Participant">
            <SelectParameters>
                <asp:ProfileParameter Name="ClientID" PropertyName="ClientID" DefaultValue="-1" Type="Int32" />
                <asp:SessionParameter Name="PlanID" SessionField="PlanID" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    </asp:Content>
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. MBEN
    MBEN avatar
    159 posts
    Member since:
    Nov 2011

    Posted 19 Nov 2011 Link to this post

    Hi ,

    Any update on this one. I am not able to do the validations.
  5. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 21 Nov 2011 Link to this post

    Hi Mben,

    I wasn't able to run your sample code. From the provided markup I noticed that the RadComboPlan's property AutoPostBack is set to true. It means that when you select an item, a postback will be triggered. The custom validation is triggered before the postback.

    Best wishes,
    Peter Filipov
    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
  6. MBEN
    MBEN avatar
    159 posts
    Member since:
    Nov 2011

    Posted 21 Nov 2011 Link to this post

    I see the issue now.
    But my second combo RadComboParticipant is loaded based on the selection in the radComboPlan. I populate the value in session variable which is read by the datasource of RadComboPlan.
    How can I avoid the postback?
  7. MBEN
    MBEN avatar
    159 posts
    Member since:
    Nov 2011

    Posted 22 Nov 2011 Link to this post

    Please provide some help on this issue.
  8. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 24 Nov 2011 Link to this post

    Hi Mben,

    When the AutoPostBack property of the radComboPlan is set to 'true' and every time you select an item from it, a postback is triggered. To avoid the postback please set it to 'false'.

    Best wishes,
    Peter Filipov
    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
  9. MBEN
    MBEN avatar
    159 posts
    Member since:
    Nov 2011

    Posted 24 Nov 2011 Link to this post

    If I set the autopostback property to false my second combo box does not get populated.
  10. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 29 Nov 2011 Link to this post

    Hello Mben,

    Please send me a working sample project that demonstrates your problem and detailed description what exactly you want to achieve. That will be the fastest way to find out a solution about your scenario.

    Greetings,
    Peter Filipov
    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017