[英]Get value from Session or ViewState in AjaxFileUpload events from AjaxToolkit
我正在嘗試通過AjaxFileUpload上傳文件,我已經完成了。 但是現在我還需要知道2個參數,URL上給出1個adreess myPage.aspx?parameter = 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));
}
}
如果嘗試使用例如?id = 12的參數運行aspx,則應將其存儲在Recid中,並且將輸入字段中的值也存儲在hiddenValue中。
但是,當我上傳文件(事件OnUploadStart或OnUploadComplete)時,我無權訪問這些值,我也嘗試了Session,但它也沒有起作用。
到目前為止,AjaxFileUpload不會在最新發布的版本15.1.4中保留查詢字符串參數。
但是,您可以在已解決此問題的情況下下載並編譯源代碼 ,並且AjaxFileUpload保留查詢字符串參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.