使用C#在asp.net中没有得到在ViewState中的价值? [英] Not getting value in Viewstate in asp.net using C#?
本文介绍了使用C#在asp.net中没有得到在ViewState中的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是asyncfileupload控制上传文件有我走路径视图状态是这样的:
I am using a asyncfileupload control to upload a file there i am taking the path in a view state like this:
protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
string name = System.IO.Path.GetFileName(e.FileName);
string dir = Server.MapPath("upload_eng/");
string path = Path.Combine(dir, name);
ViewState["path"] = path;
engcertfupld.SaveAs(path);
}
现在,当我试图保存在ButtonClick事件我没有得到视图状态的值路径:
Now when i am trying to save that path in a buttonclick event i am not getting the value of viewstate:
protected void btnUpdate_Click(object sender, EventArgs e)
{
string filepath = ViewState["path"].ToString(); // GETTING NULL in filepath
}
在此文件路径我得到空其实我得到错误空引用异常
In this filepath i am getting null actually i am getting error NULL REFERENCE EXCEPTION
现在我该怎么办?
推荐答案
把路径值在的对话 对象,而不是ViewState中,像这样的:
Put the Path value in the Session object instead of the ViewState, like this:
protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
....
string path = Path.Combine(dir, name);
Session["path"] = path;
}
然后在按钮点击:
Then in the Button Click:
protected void btnUpdate_Click(object sender, EventArgs e)
{
if (Session["path"] != null)
{
string filepath = (string) Session["path"];
}
}
这篇关于使用C#在asp.net中没有得到在ViewState中的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文