0
我想通過AjaxFileUpload上傳文件,我已經完成了。但是現在我還需要知道2個參數,1給出了URL的adreess myPage.aspx?parameter = 2從AjaxFileUpload事件中獲取來自Session或ViewState的值來自AjaxToolkit
第二個是在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 ameter例如?id = 12它應該存儲在Recid中,輸入字段的值也應該存儲在hiddenValue中。
但是當我上傳文件(事件OnUploadStart或OnUploadComplete)我沒有訪問這些值,我也試過會話,但它也沒有奏效。