public class EMSWebReports : System.Web.UI.WebControls.WebParts.WebPart
{
private Control mReportUserControl;
public EMSWebReports()
{
this.ExportMode = WebPartExportMode.NonSensitiveData;
}
protected override void Render(HtmlTextWriter writer)
{
//base.Render(writer);
try
{
this.mReportUserControl.RenderControl(writer);
}
catch (Exception e)
{
//To log the error message.
}
}
protected override void CreateChildControls()
{
//base.CreateChildControls();
try
{
this.Controls.Clear();
this.mReportUserControl = this.Page.LoadControl("~/_controltemplates/EMSControls/EMSWebReport.ascx");
this.Controls.Add(this.mReportUserControl);
}
catch (Exception e)
{
//To log the error message.
}
}
以上是我编写的一个WebPart代码示例, EMSWebReport.ascx 是我自定义的一个用户控件。现在存在的问题是,在我自定义的用户控件上有几个按钮 。然后将WebPart 添加到Sharepoint Server 2007中,其中的部分按钮事件在第一次点击的时候是可以正常触发的,但是经过第一次的点击后,页面上的全部按钮事件就不能再触发点击事件了。 各位大侠帮我看看这是什么原因。。。 先谢谢
1 protected void ButtonExportToExcel_Click(object sender, EventArgs e)
2 {
3 string reportToExeclName = this.ExportFileName();
4 DataSet ds = new DataSet();
5 ds = (DataSet)Session["ReportData"];
6 if (ds == null)
7 {
8 LabelMessages.Text = "The data has expired, please refresh!";
9 }
10 // Response.Clear();
11 // Response.Buffer = false;
12 // Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
13 Response.AppendHeader("content-disposition", "attachment;filename=" + reportToExeclName + ".xls");
14 Response.ContentType = "application/octet-stream";
15
16 for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
17 {
18 string rowString = ds.Tables[0].Rows[i]["REPORT_ROW"].ToString();
19 string[] rowStringSplit = System.Text.RegularExpressions.Regex.Split(rowString, "\\\\n");
20 for (int j = 0; j < rowStringSplit.Length; j++)
21 {
22 string rowData = rowStringSplit[j].Replace("\\n", "");
23 rowData = rowData.Replace("\\t", "\t\t");
24 rowData = rowData.Replace(" ", "") + "\n";
25 Response.Write(rowData);
26 }
27 }
28 Response.Flush();
29 //Response.End();
30 }
1
2 protected void ButtonExportToPdf_Click(object sender, EventArgs e)
3 {
4 this.DelPdfFile();
5 string reportToPdfPdth = AppDomain.CurrentDomain.BaseDirectory + "pdf\\" + this.ExportFileName() + ".pdf";
6 DataSet ds = new DataSet();
7 ds = (DataSet)Session["ReportData"];
8 if (ds == null)
9 {
10 LabelMessages.Text = "The data has expired, please refresh!";
11 }
12 Document document = new Document(PageSize.A4, 30, 30, 5, 5);
13 PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(reportToPdfPdth, FileMode.Create));
14 try
15 {
16 document.Open();
17 for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
18 {
19 string rowString = ds.Tables[0].Rows[i]["REPORT_ROW"].ToString();
20 string[] rowStringSplit = System.Text.RegularExpressions.Regex.Split(rowString, "\\\\n");
21 for (int j = 0; j < rowStringSplit.Length; j++)
22 {
23 string rowData = rowStringSplit[j].Replace("\\n", "");
24 rowData = rowData.Replace("\\t", "\t\t\t");
25 rowData = rowData.Replace(" ", "") + "\n";
26 document.Add(new Phrase(rowData));
27 }
28 }
29 }
30 catch (Exception)
31 {
32 throw;
33 }
34 finally
35 {
36 document.Close();
37 writer.Close();
38 }
39 try
40 {
41 String FullFileName = reportToPdfPdth;
42 FileInfo DownloadFile = new FileInfo(FullFileName);
43 // Response.Clear();
44 //Response.Buffer = false;
45 string dd = System.Web.HttpUtility.UrlEncode(DownloadFile.FullName);
46 Response.AppendHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(DownloadFile.FullName));
47 Response.ContentType = "application/octet-stream";
48 Response.WriteFile(DownloadFile.FullName);
49 }
50 catch (Exception)
51 {
52 throw;
53 }
54 finally
55 {
56 Response.Flush();
57 // System.Web.HttpContext.Current.Response.End();
58
了。。。
1 protected void ButtonExportToText_Click(object sender, EventArgs e)
2 {
3 string reportToTextName = this.ExportFileName();
4 DataSet ds = new DataSet();
5 ds = (DataSet)Session["ReportData"];
6 if (ds == null)
7 {
8 LabelMessages.Text = "The data has expired, please refresh!";
9 return;
10 }
11 // Response.Clear();
12 // Response.Buffer = false;
13 // Response.ContentType = "application/octet-stream";
14 Response.AppendHeader("content-disposition", "attachment;filename=" + reportToTextName + ".txt");
15
16 for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
17 {
18 string rowString = ds.Tables[0].Rows[i]["REPORT_ROW"].ToString();
19 string[] rowStringSplit = System.Text.RegularExpressions.Regex.Split(rowString, "\\\\n");
20 for (int j = 0; j < rowStringSplit.Length; j++)
21 {
22 string rowData = rowStringSplit[j].Replace("\\n", "");
23 rowData = rowData.Replace("\\t", "\t\t");
24 rowData = rowData.Replace(" ", "");
25 Response.Write(rowData + "\r\n");
26 }
27 }
28 Response.Flush();
29 //Response.End();
30 }
有可能不是按钮点击失效,而是每次点击按钮都是相同的操作,取出了相同的数据来显示,因此感觉第一次点过后再点就没反应了。
这个事件适用于任何按钮 所以只有有一个按钮触发了事件 其他的按钮都用不了了