【问题标题】:AjaxFileUpload : Getting the selected value of RadioButtonListAjaxFileUpload : 获取 RadioButtonList 的选定值
【发布时间】:2013-03-15 03:27:54
【问题描述】:

使用 autoPostBack = true 创建的两个 radiobuttonlist(semesterList 和 sem1course)。

当我单击一个学期列表项目时,相应的 sem1course 项目变得可见。

现在

    protected void UploadComplete(Object sender,   AjaxControlToolkit.AjaxFileUploadEventArgs      e)
   {

   string sem = semesterList.SelectedValue;
   string course = sem1course.SelectedValue;
   string path = Server.MapPath("~/MCA/" + sem+ "/" +course +"/")+e.FileName;
   AjaxFileUpload1.SaveAs(path);
   } 

字符串 sem 和 course 没有获得选定的值,这就是为什么所有文件都上传到 ~/MCA/ 文件夹而不是进入相应的文件夹..

上传的文件应该到" MCA\Sem1\MCA101\ " [我设计了目录结构但是文件上传到了MCA文件夹]..

【问题讨论】:

    标签: c# asp.net file-upload asp.net-ajax ajaxcontroltoolkit


    【解决方案1】:

    调用 AjaxFileUpload OnUploadComplete 事件时,问题是 Request.Form["__VIEWSTATE"] = null

    修复此问题(C# 代码):

    在页面加载时在会话中设置 RadioButtonList 选定值。

    protected void Page_Load(object sender, EventArgs e)
    {
     if (Request.Form["__VIEWSTATE"] != null)
        Session["Path"] = "//" + semesterList.SelectedValue + "//" + sem1course.SelectedValue + "//";
    }
    

    使用会话值创建文件路径:

    protected void upload(Object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
            string path = string.Empty;
            if (Session["Path"] != null)
                path = Server.MapPath("~//MCA" + (string)Session["Path"]) + e.FileName;
    }
    

    【讨论】:

    • @KPL...我做了同样的..使用会话来存储选定的值,现在它正在工作..谢谢..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 2013-05-14
    相关资源
    最近更新 更多