[英]How to get selected dropdownvalue in AjaxFileUpload onuploadComplete event?
<%@ 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>
Event Code.. 事件代码
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
}
//Both s and t get the first value of Dropdownlist even if some other value selected and that's uploading is not done as per directort structure. // s和t都将获得Dropdownlist的第一个值,即使未选择其他某些值且该上载未按照目录结构完成。
Both Dropdownlist have several values and postback property is true for both the list. 两个Dropdownlist都有多个值,并且两个列表的postback属性均为true。
How to get the exact selected value of list ? 如何获得列表的确切选择值?
Issue is Request.Form["__VIEWSTATE"] = null
when AjaxFileUpload OnUploadComplete event is called. 当调用AjaxFileUpload OnUploadComplete事件时,问题是Request.Form["__VIEWSTATE"] = null
。
Fix for this issue (C# Code): 解决此问题的方法 (C#代码):
Set dropdown selection in session at page load. 在页面加载时在会话中设置下拉选择。
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["__VIEWSTATE"] != null)
Session["Path"] = "//" + DropDownList1.SelectedValue + "//" + DropDownList2.SelectedValue + "//";
}
Use session value for the creation of filepath: 使用会话值创建文件路径:
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;
}
我相信您需要将下拉列表添加到与上传控件相同的更新面板中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.