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

RadASyncUpload in an updatepanel of radwindow is giving syntax error in SharePoint webpart

5 Answers 165 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Harish
Top achievements
Rank 1
Harish asked on 01 Feb 2012, 10:38 PM

I have telerik 2011.3.1305.35 -> Q3.
In a sharepoint 2010 visual webpart I have a RadTreeView control, when some particular menu options are selected I want to open radwindow(s) which has an asp:updatepanel and within which I have another radtree,radgrid,repeator, RadAynscUpload (not all in same window).
Folowing is the code I have for this requirement:
Issues I am facing currently:
1) Every time I click on any of these menu options the page is getting refreshed and then radwindow is getting opened, Can we avoid page refresh and just simple open radwindow?
2) One of these RadWindows has RadAsyncUpload (for multiple file uploads), when I select the files to be uploaded I am getting a javascript error saying 'Syntax error' but I can see the file uploaded to the control then when I click on the Upload button my code says the uploadedfiles count is zero. I know there are web.config changes to be done for radupload is that the same case for RadAsyncUpload, can you please specify those?
I have also tried asp:fileupload (even though its not multiple upload) it is uploading the documents correctly but it is closing the radwindow even though I specified trigger for the button.
Code:



protected
void rtvDocuments_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
        {
  
            RadTreeNode clickedNode = e.Node;
  
            switch (e.MenuItem.Value)
            {
               case "AddDoc":
                    LoadAllGroups(rtvGroupstoAddDocs);
                    RegisterStartupScript(RadWndwUploadDocs.ClientID);
                    break;
                case "AddExistingGroup":
                    LoadAllGroups(rtvAllGroups); //loads all the groups
                    RegisterStartupScript(winGroupBrowse.ClientID);
                    break;
                case "AddExistingDoc":
                    LoadAllDocuments(); //loads all docs in grid
                    RegisterStartupScript(RadWndwAllDocs.ClientID);
                    break;
                //Other Cases here
             }
  
private void RegisterStartupScript(string RadControlId)
        {
            string script = string.Empty;
            script = "function f(){$find(\"" + RadControlId + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
        }
  
//If files uploaded and on upload button click, submit the documents to repeator and then upload them to SP document library.
//I tried both the control, when debugging AsyncUpload count is zero and getting "syntax error" on the page
//FileUpload uploads succesfully but closes the radWindow, but I want the window to be showing up, If this is the only solution and if RadAsyncUpload is not helpful for me.
        protected void SubmitButton_Click(object sender, System.EventArgs e)
        {
//If RadAsyncUpload is used.. I want this to be working because of multi uploads requirement.
            if (RadAsyncUpload1.UploadedFiles.Count > 0)
            {
  
                labelNoResults.Visible = false;
                Repeater1.Visible = true;
                Repeater1.DataSource = RadAsyncUpload1.UploadedFiles;
                Repeater1.DataBind();
  
                List<string> lstFileNames = new List<string>();
                foreach (UploadedFile file in RadAsyncUpload1.UploadedFiles)
                {
                    lstFileNames.Add(file.FileName);
  
                }
                //AddedControl ISODocuments to SharePoint document library
                AddDoc(lstFileNames);
  
            }
            else
            {
                labelNoResults.Visible = true;
                Repeater1.Visible = false;
            }
  
//If file upload is used.
 if (FileUpload1.PostedFile != null)
            {
                string siteUrl = SPContext.Current.Site.Url;
                using (SPSite siteColl = new SPSite(siteUrl))
                {
                    //Get SPWeb object representing a particular website
                    using (SPWeb webSite = siteColl.OpenWeb())
                    {
                        try
                        {
                            webSite.AllowUnsafeUpdates = true;
                            webSite.Lists.IncludeRootFolder = true;
                            //Get the document library in which documents will be uploaded
                            SPList docLibrary = webSite.Lists["UpLoadedDocuments"];
                            // objFileUpload is asp.net FileUpload Object
                            Stream FStream; string fname;
                            FStream = FileUpload1.PostedFile.InputStream;
                            int basenamestart = FileUpload1.PostedFile.FileName.LastIndexOf(@"\");
                            fname = FileUpload1.PostedFile.FileName.Substring(basenamestart + 1);
                            //Upload files into SharePoint document library
                            SPFile file = docLibrary.RootFolder.Files.Add(fname, FStream, true);
  
                            file.Update();
                        }
                        catch
                        { }
                    }
                }
            }
  
  
        }
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ABC.ascx.cs"
    Inherits="X.Y.Z" %>
<%@ Register Assembly="Telerik.Web.UI, Version=2011.3.1305.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
    Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
  
     
   <telerik:RadScriptBlock runat="Server" ID="RadScriptBlock2">
        <script type="text/javascript">
    </script>
         <script type="text/javascript" src="/_layouts/js/MyCustom.js"></script>  
    </telerik:RadScriptBlock>
  
<telerik:RadTreeView ID="rtvDocuments" runat="server" EnableDragAndDrop="True" OnNodeDrop="rtvDocuments_HandleDrop"
        OnClientNodeDropping="onDropping" OnClientNodeDragging="onNodeDragging" MultipleSelect="true"
        EnableDragAndDropBetweenNodes="true" OnNodeExpand="rtvDocuments_NodeExpand" AllowNodeEditing="true"
        OnContextMenuItemClick="rtvDocuments_ContextMenuItemClick" OnNodeEdit="rtvDocuments_NodeEdit">
        <ContextMenus>
            <telerik:RadTreeViewContextMenu CssClass="ctxTreeMenu" ID="cMenuForGroups" runat="server">
                <Items>
                    <telerik:RadMenuItem Value="Rename" Text="Rename ..." Enabled="false" ImageUrl="/_layouts/Img/Outlook/rename.gif"
                        PostBack="false">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Value="NewFolder" Text="New Group"  ImageUrl="/_layouts/Img/Outlook/12.gif">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Value="AddDoc" Text="Add New Document" ImageUrl="/_layouts/Img/Outlook/journal.gif">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Value="Delete" Text="Delete Group" ImageUrl="/_layouts/Img/Outlook/7.gif">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem IsSeparator="true">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Value="Copy" Text="Clone ..." ImageUrl="/_layouts/Img/Outlook/10.gif">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Value="AddExistingGroup" Text="Add Existing Group">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Value="AddExistingDoc" Text="Add Existing Document">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Value="ViewAll" Text="View all Instances of ..." ImageUrl="/_layouts/Img/Outlook/searchFolder.gif">
                    </telerik:RadMenuItem>
                </Items>
                <CollapseAnimation Type="OutBack" />
            </telerik:RadTreeViewContextMenu>
</ContextMenus>
    </telerik:RadTreeView>
  <telerik:RadWindow ID="winGroupBrowse" runat="server"  EnableViewState="false"  Modal="true" Overlay="true" Width="875px" Height="545px"
     EnableShadow="true" DestroyOnClose="true" ShowContentDuringLoad="false" ReloadOnShow="true">
    <ContentTemplate>
           <div id="globalTree" class="globalTreeCont">
                <asp:UpdatePanel ID="pnlTree" Visible="true" runat="server">
                <ContentTemplate>
                    <telerik:RadTreeView CssClass="globalTree" OnNodeExpand="rtvDocuments_NodeExpand"
                        ID="rtvAllGroups" runat="server">
                    </telerik:RadTreeView>
                    </ContentTemplate>
                </asp:UpdatePanel>
    </ContentTemplate>
</telerik:RadWindow>
  <telerik:RadWindow ID="RadWndwAllDocs" runat="server"  EnableViewState="false"  Modal="true" Overlay="true" Width="875px" Height="545px"
     EnableShadow="true" DestroyOnClose="true" ShowContentDuringLoad="false" ReloadOnShow="true">
    <ContentTemplate>
                <asp:UpdatePanel ID="pnlGrid" Visible="true" runat="server">
                  <ContentTemplate>
                    <telerik:RadGrid ID="rgrdAllDocs" runat="server" AutoGenerateColumns="false" AllowFilteringByColumn="true"
                        AllowPaging="true" PageSize="10" AllowSorting="true" Height="100%" Width="100%">
                        <PagerStyle Mode="NextPrevAndNumeric"  />
                        <MasterTableView Height="100%" Width="100%">
                            <Columns>
                                <telerik:GridBoundColumn HeaderText="ID" DataField="ID" />
                                <telerik:GridBoundColumn HeaderText="Title" DataField="Title" />
                                <telerik:GridBoundColumn HeaderText="Description" DataField="Description" />
                                <telerik:GridBoundColumn HeaderText="ISOGroups" DataField="ISOGroupText" />
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                      </ContentTemplate>
                </asp:UpdatePanel>
                    </ContentTemplate>
</telerik:RadWindow>
  <telerik:RadWindow ID="RadWndwUploadDocs" runat="server"  EnableViewState="false"  Modal="true" Overlay="true" Width="875px" Height="545px"
     EnableShadow="true" DestroyOnClose="true" ShowContentDuringLoad="false" ReloadOnShow="true">
    <ContentTemplate>
               <asp:UpdatePanel ID="pnlUpload" Visible="true" runat="server" UpdateMode="conditional">
                                           <%-- If file upload is used instead of radAsyncUpload UNCOMMENT the trigger
                                             <Triggers>
                                               <asp:PostBackTrigger ControlID="SubmitButton" />
                                              </Triggers> --%>
                   <ContentTemplate>
                    <div class="grid grid_18 wizardMargin">
                    <div id="uploadCont">
                            <div class="columns">
                                <div class="col1">
                                    <h4>
                                        Groups on Page</h4>
                                    <div class="treeCont">
                             <telerik:RadTreeView CssClass="globalTree" OnNodeExpand="rtvDocuments_NodeExpand"
                        ID="rtvGroupstoAddDocs" runat="server"></telerik:RadTreeView>
                                    </div>
                                </div>
                                <div class="col2">
                                    <h4>
                                        Uploaded Files</h4>
                                    <div class="fileTree">
                                        <asp:Label ID="labelNoResults" runat="server" Visible="True">No uploaded files</asp:Label>
                                        <asp:Repeater runat="server" ID="Repeater1">
                                            <ItemTemplate>
                                                <div class="fileListStyle">
                                                    <%# DataBinder.Eval(Container.DataItem, "FileName").ToString() %>  (<%# DataBinder.Eval(Container.DataItem, "ContentLength").ToString() %>bytes)<br />
                                                </div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </div>
                                </div>
                            </div>
                            <div class="uploadControls">
                                <h4>
                                    Select Files to Upload</h4>
                                <div class="FileDetails">
                                    <table class="uploadTable">
                                        <tbody>
                                            <tr>
                                                <td class="uploader">                                                
                                             <telerik:RadAsyncUpload runat="server" ID="AsyncUpload1" Skin="default">
                                                </telerik:RadAsyncUpload>
                                              
                                             //Tried asp fileupload, it is uploading files to document library and closing the radwindow.I donot want it to close it.
                                          //       <asp:FileUpload ID="FileUpload1" runat="server"  />
                                                    <asp:Button runat="server" ID="SubmitButton" Text="Upload files" OnClick="SubmitButton_Click" />  
                                           
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                         </div>
                   </ContentTemplate>
                </asp:UpdatePanel>
      </ContentTemplate>
   </telerik:RadWindow>

Any help is appreciated.

5 Answers, 1 is accepted

Sort by
0
Harish
Top achievements
Rank 1
answered on 02 Feb 2012, 02:18 AM
I have added the radprogressmanager and radprogressarea to RadAsyncUpload and updated my web.config file and disabled the flash dependency as mentioned in few blogs eg:
http://www.telerik.com/support/kb/aspnet-ajax/upload/906-ajax-callback-error.aspx and
http://www.telerik.com/community/forums/aspnet-ajax/upload/radasyncupload-control-asking-for-login-in-sharepoint.aspx

But still RadProgressArea never stops loading and I get the same 'Syntax error' (Please find the attachment), What else I am missing?



<
telerik:RadProgressManager runat="server" ID="RadProgressManager1" />  
                                               <script type="text/javascript">
                                                   Telerik.Web.UI.RadAsyncUpload.Modules.Flash.isAvailable = function () { return false; }
  
                                               </script>
                                                           
                                               <telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" OnFileUploaded="fileUploaded" />  
                                               <telerik:RadProgressArea runat="server" ID="RadProgressArea1" />  
                                                                                                                                    
                                                <%--<asp:FileUpload ID="FileUpload1" runat="server"  />--%>
                                                   <asp:Button runat="server" ID="SubmitButton" Text="Upload files" OnClick="SubmitButton_Click" />  
0
Cat Cheshire
Top achievements
Rank 1
answered on 07 Feb 2012, 09:56 AM
You can add the AsyncUpload and ProgressManager to a new VisualWebPart.
Then you can test if the upload works (uploads files) firstly with,  and then without the ProgressManager(simply remove it from the webpart) – I am sure that this will help you find out what causes the error.
0
Rohan
Top achievements
Rank 1
answered on 10 Aug 2012, 02:58 PM
Hi all,

I have one rad window with RadAsyncUpload and one asp.net button in window . i want to create -- after user click on the button the file is uploaded on server and rad widow gets close. i was completed this task ...but my problem is after the clicking to button my page gets postback and reloaded any way to stop to reload hole page .
0
Harish
Top achievements
Rank 1
answered on 10 Aug 2012, 04:43 PM
I tried using Updatepanels -> Control templates -> Uplad button and outside button panel I used triggers which takes care of postback.....I think it works in ASP.net application, but if you are into Sharepoint and opening a usercontrol in radwindow then this wonot work, meaning you would not see the flicker (postback) but the document will not get uploaded and hence I created an application page and opened it in radwindow and hence on button click my application page will get refreshed not my original page ....
0
Plamen
Telerik team
answered on 15 Aug 2012, 08:31 AM
Hi,

I tried to reproduce the issue you described but to no avail. Would you please share the exact isolated code that will help us observe the described issue that works properly in ASP.net application and does not work in SharePoint? Please remove all the controls and code that are not directly connected to the issue so we can inspect it and be more helpful.

Regards,
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.
Tags
AsyncUpload
Asked by
Harish
Top achievements
Rank 1
Answers by
Harish
Top achievements
Rank 1
Cat Cheshire
Top achievements
Rank 1
Rohan
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or