I am having trouble trying to write a member of an instance of my page's class when using the Ajax timer control.
I built a very simple rough example below which the exact problem I am facing is emulated ...
The code below uses the UpdateText method each time using a timer. Each time a method is called, it increments the count variable by one to illustrate how many times the timer control has called back.
Of course, in order to read the counter value on a web page, the shortcut is inside the update panel using a trigger associated with a timer.
Markup:
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="UpdateText">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label runat="server" Text="" ID="lblCounter"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
CodeBehind:
public partial class TimerControl : System.Web.UI.Page
{
private static int loopCounter = 0;
protected void Page_Load(object sender, EventArgs e)
{
}
public void UpdateText(object sender, EventArgs e)
{
lblCounter.Text = loopCounter.ToString();
loopCounter++;
}
}
, , , , , 'loopCounter' , , / .
, loopCounter , ... (JavaScript) .
, , , , .
- , "" ? ?