我宣布了我的名单" lijstBijlagen"在我的班级的顶部,所以我将能够在该类的所有方法中使用它。现在的问题是我在方法中填写了这个列表" btnUpload_Click"但是当我想在方法btnSubmit_Click中使用它时,它再次变为空。我在本文下面的代码中遗漏了我的Page_Load代码,因为我认为您不需要它来解决问题。
namespace Veiligheidsplan.WebUI
{
public partial class MailPage : System.Web.UI.Page
{
private List<string> lijstBijlagen = new List<string>();
protected void btnSubmit_Click(object sender, EventArgs e)
{
List<string> parts = txtOntvangers.Text.Split(',').Select(p => p.Trim()).ToList();
MailService.SendMail(parts, txtOnderwerp.Text, txtBody.Text, lijstBijlagen);
Server.Transfer("Homepage.aspx");
}
protected void btnUpload_Click(object sender, EventArgs e)
{
string bijlage = ddlBijlagen.SelectedItem.Text;
string bijlagePad = "~/Veiligheidsplan/" + Session["IngelogdeGebruikersnaam"]+"/" + bijlage;
lijstBijlagen.Add(bijlagePad);
lblCommentaar.Visible = true;
lblCommentaar.Text += ", "+bijlage;
}
}
}
答案 0 :(得分:0)
You will need to persist your list every postback.