c#试图从另一个方法访问某些东西

时间:2013-05-16 03:25:30

标签: c# ajax

我是新手,所以希望你们和我一起忍受。我试图在btnDone上插入filePathImage的URL目录到数据库。 部分代码:

  protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        EnsureDirectoriesExist();


        String filepathImage = (@"Images/Story/" +txtTitle.Text + "/" + e.FileName);


        AjaxFileUpload1.SaveAs(Server.MapPath(filepathImage));


    }

 protected void btnDone_Click(object sender, EventArgs e)
    {

        act.ActivityName = dropListActivity.SelectedItem.Text;
        act.Title = txtTitle.Text;

        act.FileURL = filepathImage;

        daoStory.Insert(act);
        daoStory.Save();
    }

我在act.FileURL = AjaxFileUpload1.filePathImage中遇到了filePathImage的问题;任何建议或解决方案都将不胜感激

1 个答案:

答案 0 :(得分:1)

尝试下面的内容,上传完成后,您可以将路径放入会话中,并在需要时获取该会话路径。

protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{

  // your Code 
  Session["filepathImage"] = filepathImage ; // put the path in session variable 

}

protected void btnDone_Click(object sender, EventArgs e)
{
    if(Session["filepathImage"]!=null)
    {
         string filepathImage = Session["filepathImage"] as string;
         // your code ...
    }
}