<form id="viewReportForm" name="viewReportForm" method="post" runat="server">
<input type="button" value="" id="reportSearch" name="reportSearch" value="查询报表" class="rptSearch" onclick="OnReportSearchClick()" />
<iframe id="frmViewerCrReport" />
</form>
有两个页面。 一个是View.aspx 另一个是"ShowCrystalReportViewer.aspx
//查询报表
function OnReportSearchClick()
{
viewReportForm.method = "post";
viewReportForm.action = location.href;
viewReportForm.submit();
//提供数据到IFrame 中
viewReportForm.method = "post";
viewReportForm.target = "frmViewerCrReport";
viewReportForm.action = "ShowCrystalReportViewer.aspx?t="+ Math.random();
viewReportForm.submit();
}
说明: "ShowCrystalReportViewer.aspx 接收View.aspx post过去的参数, 根据参数来展示水晶报表
问题: 点击 查询报表按钮时, 先候会触发 View.aspx的Page_Load和ShowCrystalReportViewer.aspx的Page_Load事件。
我在页基类的 protected override void Render(HtmlTextWriter writer)
{
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
base.Render(htmlWriter);
string html = stringWriter.ToString();
#region ViewState
int startPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");
if (startPoint >= 0)
{
int endPoint = html.IndexOf("/>", startPoint) + 2;
string viewStateInput = html.Substring(startPoint, endPoint - startPoint);
html = html.Remove(startPoint, endPoint - startPoint);
int formEndStart = html.IndexOf("</form>", startPoint);
if (formEndStart >= 0)
{
html = html.Insert(formEndStart, viewStateInput);
}
}
#endregion
#region 辅助输出信息
StringBuilder sb = new StringBuilder("");
foreach (string sKey in m_dicHiddens.Keys)
{
sb.AppendFormat("<input type=\"hidden\" id=\"{0}\" name=\"{0}\" value=\"{1}\" />\n", sKey, m_dicHiddens[sKey]);
}
if (sb.Length >= 1)
{
int nLastIndex = html.LastIndexOf("</form>");
if (nLastIndex == -1)
{
nLastIndex = html.LastIndexOf("</body>");
}
html = html.Insert(nLastIndex, "\n" + sb.ToString());
}
//脚本
if (m_sbAppendScriptToEndBody.Length > 0)
{
sb = new StringBuilder("");
sb.AppendLine("<script type=\"text/javascript\">");
sb.AppendFormat(" {0}", m_sbAppendScriptToEndBody.ToString());
sb.AppendLine("</script>");
int nLastIndex = html.LastIndexOf("</body>");
html = html.Insert(nLastIndex, "\n" + sb.ToString());
}
#endregion
writer.Write(html); // 这里我监测到会触发两次。首先是View.aspx 其次是ShowCrystalReportViewer.aspx
// 比如 View.aspx触发时。生成<h>新的</h>
// 可真正生成的页面却还是上次没触发的页面数据。
}
没太明白你的问题究竟是什么。
每次页面回发时,都会重新执行页面的各个生命周期的,所以你回发时就会遇到两次触发的情况,如果数据没有正确变更,猜想可能是你的页面在重新执行生命周期的时候又将一些数据初始化了。
OnReportSearchClick有点问题吧,怎么出现两次submit了