我试图通过AjaxFileUpload上传文件,我已经完成了。但是现在我还需要知道2个参数,1是在URL adreess myPage.aspx上给出的?参数= 2
第二个是ViewState。
但是在事件OnUploadStart或OnUploadComplete
上当我尝试会话时,我无法访问这些值事件。
我该如何解决这个问题?
这是我的ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutoUpload.aspx.cs" Inherits="AutoUpload" %>
<%@ Register TagPrefix="ajaxToolkit" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit, Version=15.1.4.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="scripts/jquery-1.3.2.min.js"> </script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:TextBox runat="server" ID="txtValue"></asp:TextBox>
<asp:Button runat="server" ID="btnSetValue" Text="set" OnClick="btnSetValue_OnClick"/>
<asp:HiddenField runat="server" ID="hiddenValue"/>
<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload" MaximumNumberOfFiles="50" AllowedFileTypes="jpg,jpeg" OnUploadComplete="AjaxFileUpload_OnUploadComplete" OnUploadStart="AjaxFileUpload_OnUploadStart" runat="server" />
</div>
</form>
这是我的服务器端
using System;
using AjaxControlToolkit;
public static class Validators
{
public static bool IsNumeric(this string value)
{
int myInt;
bool isNumerical = int.TryParse(value, out myInt);
return isNumerical;
}
}
public partial class AutoUpload : System.Web.UI.Page
{
public int Recid
{
get
{
if ((ViewState["Recid"] != null) && ((ViewState["Recid"].ToString()).IsNumeric()))
return Convert.ToInt32(ViewState["Recid"]);
return 0;
}
set { ViewState["Recid"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["id"];
if (!string.IsNullOrEmpty(id) && id.IsNumeric())
Recid = Convert.ToInt32(id);
}
protected void btnSetValue_OnClick(object sender, EventArgs e)
{
hiddenValue.Value = txtValue.Text.ToString();
}
protected void AjaxFileUpload_OnUploadStart(object sender, AjaxFileUploadStartEventArgs e)
{
int myId = Recid; // THIS IS ALWAYS 0
string otherValue = hiddenValue.Value;
}
protected void AjaxFileUpload_OnUploadComplete(object sender, AjaxFileUploadEventArgs e)
{
int myId = Recid; // THIS IS ALWAYS 0
string otherValue = hiddenValue.Value;
AjaxFileUpload.SaveAs(Server.MapPath("~/" + e.FileName));
}
}
如果您尝试使用参数运行aspx,例如?id = 12,则应将其存储在Recid中,输入字段中的值也应存储在hiddenValue中。
但是当我上传文件(事件OnUploadStart或OnUploadComplete)时,我无权访问这些值,我也尝试了Session,但它也没有用。
答案 0 :(得分:1)
到目前为止,AjaxFileUpload不会在最新发布的15.1.4版本中保留查询字符串参数。
但是,您可以下载并编译已解决此问题的source code,并且AjaxFileUpload会保留查询字符串参数。