我更改了 Web 用户控件中的公共属性,但客户端看不到该更改,直到我删除用户控件并重新添加它,然后它才看到更改。
我在想,如果在很多地方都使用了用户控件,我是否必须对所有页面都这样做?当然,我错过了什么?
这是我的 webusercontrol 的代码隐藏:
public partial class ReportExporter : System.Web.UI.UserControl
{
public IEnumerable<object> DataSource { get; set; }
public String ExportFilename { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnExportCsv_Click(object sender, EventArgs e)
{
//Client needs to subscribe to this event and set the
//DataSource property with IEnumerable.
//Todo: Find other ways to show this as a requirement.
OnExportEvent(e);
if (String.IsNullOrEmpty(ExportFilename))
ExportFilename = "NeedToOverrideThisName";
Response.Clear();
Response.ContentType = "text/csv";
Response.AddHeader("Content-Disposition", "attachment; filename=" + ExportFilename + ".csv");
byte[] csvData = Utility.ToCsv(",", DataSource.ToList());
Response.OutputStream.Write(csvData, 0, csvData.Length);
HttpContext.Current.Response.End();
}
protected void BtnExportPdf_Click(object sender, EventArgs e)
{
}
public event EventHandler ExportEvent;
protected void OnExportEvent(EventArgs e)
{
if (ExportEvent != null)
{
ExportEvent(this, e);
}
}
}
我所做的只是更改 DataSource 的属性名称,它是 AnyList。