【问题标题】:How to get selected dropdownvalue in AjaxFileUpload onuploadComplete event?如何在 AjaxFileUpload onuploadComplete 事件中获取选定的下拉值?
【发布时间】:2013-03-26 09:58:39
【问题描述】:
      <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs"  Inherits="test"%>

      <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml">
       <head runat="server">
       <title></title>
      </head>
      <body style="height: 162px">
<form id="form1" runat="server">
<div>

    <asp:RadioButton ID="MCA" runat="server" Text="MCA" AutoPostBack="True" 
        oncheckedchanged="MCA_CheckedChanged" />
    <br />

</div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
    <asp:ListItem Value="Sem1"></asp:ListItem>
    <asp:ListItem Value="Sem2"></asp:ListItem>
</asp:DropDownList>
<br />
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" 
    onselectedindexchanged="DropDownList2_SelectedIndexChanged" 
    ViewStateMode="Enabled">
    <asp:ListItem Value="MCA101"></asp:ListItem>
    <asp:ListItem Value="MCA103">MCA103</asp:ListItem>
</asp:DropDownList>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
     <br />
        <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" 
            OnUploadComplete="upload"/>
    <br />
    </ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

事件代码..

      protected void upload(Object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
      {
        string s = DropDownList1.SelectedValue;
        string t = DropDownList2.SelectedValue;
        string path= string path = Server.MapPath("~/MCA/" + s + "/" +t+ "/")+e.FileName 
      }

//s 和 t 都获得 Dropdownlist 的第一个值,即使选择了其他一些值并且没有按照directort 结构完成上传。

两个下拉列表都有几个值,并且 postback 属性对于两个列表都是 true。

如何获取列表的准确选择值?

【问题讨论】:

  • 发布您的 .aspx 页面代码
  • @KPL 我发布了 .aspx 代码

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


【解决方案1】:

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

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

在页面加载时在会话中设置下拉选择。

protected void Page_Load(object sender, EventArgs e)
{
 if (Request.Form["__VIEWSTATE"] != null)
    Session["Path"] = "//" + DropDownList1.SelectedValue + "//" + DropDownList2.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;
}

【讨论】:

  • 没有变化!!文件仍在上传到 MCA\sem1\MCA101 .. 即使选择了 MCA103 ..
  • @Anony_Ask 更新了我的答案。
【解决方案2】:

我相信您需要将下拉列表添加到与上传控件相同的更新面板中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多