I’m trying to create a report host in vs2010 using asp.net. This is the first time I’ve tried doing web development so I may be making a very obvious mistake. The end goal is a host that not only shows a report to the user, but also tracks how long they are looking at the report. However, I can’t get past this annoying issue that every time my timer ticks the report is redrawn.
I have a UsageAuditor control, it’s just an update panel with a timer and a label in it:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer runat="server" ID="Timer1" Interval="3000" OnTick="Timer1_Tick"/>
<asp:Label ID="lblTime" runat="server" Text="Not updated yet"></asp:Label>
</ContentTemplate>
Then my report shell uses that control:
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<uc1:UsageAuditor ID="ua1" runat="server" />
<rsweb:reportviewer ID="reportViewer" runat="server" Font-Names="Verdana"
Font-Size="8pt" InteractiveDeviceInfos="(Collection)" ProcessingMode="Remote"
WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt"
Height="800px" Width="1000px" AsyncRendering="True">
</rsweb:reportviewer>
</form>
</body>
And the timer tick simply updates the label:
protected void Timer1_Tick(object sender, EventArgs e)
{
lblTime.Text = String.Format("Updated at {0}", DateTime.Now.ToString());
}
So I thought by definining my ReportViewer outside of the UpdatePanel the UpdatePanel would redraw iteself, but the rest of the page would not get updated. However, every time the timer ticks it redraws the report. It’s very annoying because if you have the calendar control open on the report it closes it. Currently for testing purposes the timer ticks every three seconds which is not realistic, but I still don’t want the report control getting redrawn when the user is trying to use it regardless of the interval. Any ideas?
Well I found a post saying ReportViewer and UpdatePanel do not mix:
After reading puddleglums suggestion I put some thought into why I felt I needed to use a timer to update my usage information. It really was unneccessary to upate on an interval if I could just capture when the user left the page.
Following this example I added some java script to call a server side function on close:
Added the HandleClose call on onunload and the hidden type to my body:
Then created a server side function: