我试图分配hiddenfield值获取隐藏字段值在我的Page_Load如图所示:从代码隐藏
If Session("tempDir") Is Nothing Then
If Request.Files.Count > 0 Then
Dim tempDir As String
tempDir = Path.GetRandomFileName()
tempDir = tempDir.Substring(0, tempDir.LastIndexOf("."))
IO.Directory.CreateDirectory(Server.MapPath("~/Uploads/" & tempDir))
IO.Directory.CreateDirectory(Server.MapPath("~/Downloads/" & tempDir))
Session.Add("tempDir", tempDir)
currentDirectory.Value = Session("tempDir").ToString
Dim chunk As Integer = If(Context.Request("chunk") IsNot Nothing, Integer.Parse(Context.Request("chunk")), 0)
Dim fileName As String = If(Context.Request("name") IsNot Nothing, Context.Request("name"), String.Empty)
myfilename = fileName
Session.Add("filename", myfilename)
finalfilename.Value = currentDirectory.Value & fileName
finalfilename.Value = Session("filename").ToString
MsgBox(finalfilename.Value)
workingDir.Value = Server.MapPath("~/Uploads/" & tempDir)
Session.Add("tempDir", workingDir.Value)
MsgBox(workingDir.Value)
waitFlag.Value = "True"
Session.Add("flag", waitFlag.Value)
waitFlag.Value = Session("flag").ToString
MsgBox(waitFlag.Value)
Dim fileUpload As HttpPostedFile = Context.Request.Files(0)
Dim uploadPath = Context.Server.MapPath("~/uploads/" & tempDir)
Using fs = New FileStream(Path.Combine(uploadPath, fileName), If(chunk = 0, FileMode.Create, FileMode.Append))
Dim buffer = New Byte(fileUpload.InputStream.Length - 1) {}
fileUpload.InputStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, buffer.Length)
End Using
End If
End If
这是我的HTML输入隐藏字段:
<input type="hidden" id="workingDir" runat="server"/>
<input type="hidden" id="finalfilename" runat="server"/>
<input type="hidden" id="waitFlag" runat="server"/>
<input id="currentDirectory" type="hidden" runat="server"/>
这是我的Ajax调用哪里我得到所有隐藏的字段值为undefined:
<script type="text/javascript">
$('#btnconvert').click(function() {
var wd = $('#workingDir').val();
alert(wd);
var fn = $('#finalfilename').val();
alert(fn);
var bf = $('#waitFlag').val();
alert(bf);
$.ajax({
type: "POST",
url: "Default.aspx/ProcessFiles",
data: "{'workingDir':'" + wd + "', 'finalfilename':'" + fn + "', 'waitFlag':'" + bf + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("success");
},
error: function (data) {
alert("fail");
}
});
});
</script>
任何人都可以指出我在哪里出错了吗?
你检查它的进入,因为你如果部分已经检查会话是否可用,只有它会将值分配给隐藏变量。你是否也使用autopostback检查? –
是的,因为它正在生成会话变量并将文件存储在其中,所以显然它应该有文件名权限? – coder
是的,你是否通过调试来检查这些值是否放在服务器端代码的隐藏字段中?有没有可能没有把价值。 –