Cannot get the uploaded file name while using ajax

亡梦爱人 提交于 2019-12-12 01:06:10

问题


I am using Ajax file upload control to upload file in which it works fine but when i a check box or radiobutton which has autopostback property set to true and I check then the FileName returns value null

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    try
    {
        if (AsyncFileUpload1.IsUploading)
        {
            AsyncFileUpload1.SaveAs(MapPath("~/Images/Accounts/" + AsyncFileUpload1.FileName));
        }
    }
    catch (Exception ex)
    {

    }
}

after uploading then any postback control fired it simply returns null and viewstate also not worked


回答1:


use viewstate is a server control which will be clear by using postback so first store the value in a javascript and then use it as follows

THE Java Script Method:

 function OnClientAsyncFileUploadComplete(sender, args) {
                      __doPostBack('filename', args.get_fileName());

        }

        function saveLogo(ImageName) {
            __doPostBack('filename', args.get_fileName());
        }

in page load plese put the following code:

IN .CS

           if (IsPostBack)
            {

                string eventTarget = this.Request["__EVENTTARGET"];
                if (eventTarget == "filename")
                {
                    ViewState["EIName"] = this.Request["__EVENTARGUMENT"].ToString();
                }
            }

ViewState["EIName"] contains the file name

you can use any where in the page



来源:https://stackoverflow.com/questions/16833765/cannot-get-the-uploaded-file-name-while-using-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!