简体   繁体   中英

cant use scriptManager RegisterClientScriptBlock witgh AJAX AsyncFileUpload

Using a 'ajaxToolKit:AsyncFileUpload" to upload images to my application:

<ajaxToolkit:AsyncFileUpload OnClientUploadError="uploadError"
                                OnClientUploadComplete="ajaxUploadImage_ClientUploadComplete" runat="server"
                                ID="ajaxUploadImage" Width="400px" UploaderStyle="Modern"
                                CompleteBackColor = "White"
                                UploadingBackColor="#CCFFFF"  ThrobberID="imgLoader"
                                OnUploadedComplete = "ajaxUploadImage_OnUploadComplete" 
                                 OnClientUploadStarted="AssemblyFileUpload_Started" 
                              />

the problem being I want to add a limit to the amount of images a user can upload, if the limit is succeed fire a 'attachmentLimitReachedScript' popUp from scriptManager, if not continue...but am i correct in saying you cant use a script manager from inside an ajax control...any ideas of a work around?

protected void ajaxUploadImage_OnUploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
        {
            //attachment limit has not been reached, DO NOT UPLOAD IMAGES 
            if (hasUserReachedImageUploadLimit())
            {
                return;
            }

            //attachment limit has not been reached, continue with other functionality
}

    protected bool hasUserReachedImageUploadLimit()
        {
            bool limitReached = false; 

            DataAccess.Classes.CheckPricePlan CheckCustomerAccountLimitations = new DataAccess.Classes.CheckPricePlan();
            string attachmentLimitReachedScript = CheckCustomerAccountLimitations.imageTableSize(currentUser.UserWorkspace.WorkSpaceID, currentUser.UserWorkspace.Organisation.ID);
            //if attachmentLimitReachedScript !=  "AllowedToImage", attachment limit has been reached, display popUp
            if (attachmentLimitReachedScript != "AllowedToAddAttachment")
            {
                attachmentLimitReachedScript += "(alert('end'));";
                string test = "(alert('start'));" + attachmentLimitReachedScript;
                ScriptManager.RegisterClientScriptBlock(upViewUploadImages, upViewUploadImages.GetType(), "attachmentLimitReachedScript", test, true);
                upViewUploadImages.Update();
                limitReached = true;
            }

            return limitReached;
        }

I have added an alert(start) and alert(end) before and after the script. both alerts are showing and I know the script isnt the problem because I am calling it elsewhere on the same page and it works fine

Yes, there is no option to limit number of uploading files.

You can hide or break in any way the control with client code when OnClientUploadComplete event occurs.

Or you can set Visible=false , so server-side OnPreRender() method will not be called and control will not react to sending files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM