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

wierd error with RadUpload custom validation

8 Answers 85 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
MBEN
Top achievements
Rank 2
Veteran
MBEN asked on 17 Nov 2011, 01:12 AM
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.

8 Answers, 1 is accepted

Sort by
0
MBEN
Top achievements
Rank 2
Veteran
answered on 17 Nov 2011, 08:14 PM
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>
0
MBEN
Top achievements
Rank 2
Veteran
answered on 20 Nov 2011, 01:02 AM
Hi ,

Any update on this one. I am not able to do the validations.
0
Peter Filipov
Telerik team
answered on 21 Nov 2011, 01:12 PM
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
0
MBEN
Top achievements
Rank 2
Veteran
answered on 21 Nov 2011, 06:11 PM
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?
0
MBEN
Top achievements
Rank 2
Veteran
answered on 23 Nov 2011, 12:11 AM
Please provide some help on this issue.
0
Peter Filipov
Telerik team
answered on 24 Nov 2011, 11:49 AM
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
0
MBEN
Top achievements
Rank 2
Veteran
answered on 24 Nov 2011, 08:42 PM
If I set the autopostback property to false my second combo box does not get populated.
0
Peter Filipov
Telerik team
answered on 29 Nov 2011, 12:38 PM
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
Tags
Upload (Obsolete)
Asked by
MBEN
Top achievements
Rank 2
Veteran
Answers by
MBEN
Top achievements
Rank 2
Veteran
Peter Filipov
Telerik team
Share this question
or