Monday, March 26, 2012

AJAX timer wont trigger UpdatePanel in Window Mobile 5 device

My webform WORKS FINE when published to its localhost site and I bring it up in IE7.

I have a GridView and a textbox inside an updatepanel and an AJAX timer to trigger the update.

When the AJAX timer ticks, the textbox receives the current time and the Gridview updates from its SqlDataSource.

BUT ... when I try to execute it on 1) the Pocket PC Windows Mobile 5 Emulator OR 2) on a real PPC with WM5, it just sits there static after the initial load. Manual refreshes work but the timer appears to do nothing.

I would appreciate any ideas, especially any methods to help debug the client behavior to see if that timer is indeed doing anything.

<asp:ScriptManagerID="ScrMgr1"runat="server"EnablePartialRendering="true"/><asp:TimerID="Timer1"runat="server"OnTick="Timer1_Tick1"Interval="5000"></asp:Timer><asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional">
<Triggers> <asp:AsyncPostBackTriggerControlID="Timer1"EventName="Tick"/></Triggers><ContentTemplate> <asp:GridViewID="GridView1"runat="server"DataSourceID="SqlDataSource1"></asp:GridView> <asp:LabelID="Label1"runat="server"Height="82px"Text="Label"Width="306px"></asp:Label> <asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:NautilusDBConnectionString %>"
SelectCommand="SELECT [Source], [Loads] FROM [Loads]" ProviderName="<%$ ConnectionStrings:NautilusDBConnectionString.ProviderName %>"></asp:SqlDataSource></ContentTemplate></asp:UpdatePanel>

=====================================

Code Behind

protectedvoid Timer1_Tick1(object sender,EventArgs e)

{

GridView1.DataBind(); //needed, or no data update

Label1.Text ="UpdatePanel1 refreshed at: " +DateTime.Now.ToLongTimeString();

UpdatePanel1.Update();

}

You need to setChildrenAsTriggers="false"when you want to callasp:UpdatePanel.Update()inthe timer Tick event handler.It should work fine.
Try to take a look at this document for details when calling asp:UpdatePanel.Update()method -http://ajax.asp.net/docs/mref/M_System_Web_UI_UpdatePanel_Update.aspx.
Wish this can help you.
Thanks Jasson that worked. But you didnt say why it worked in IE7 but not in Mobile 5. I made some further changes in the project
and never could get it working again even with my new knowledge from the documentation.
NOW I have the same problem using a timeras a child. It works in IE7 but a breakpoint in the timer handler
is never reached by either the PDA emulator or a real PDA ... that is in the case that I connect
to the running Visual Studio project. Same behaviour when I publish the project to IIS and connect there.
Why does it work in IE7 and not in IEMobile?
 
protectedvoid Timer1_Tick(object sender,EventArgs e)

{

GridView1.DataBind();

Label1.Text = System.

DateTime.Now.ToString();

}

==========================================================

<%

@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>Untitled Page</title>

</

head>

<

body><formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"/><br/><asp:UpdatePanelID="UpdatePanel1"runat="server"ChildrenAsTriggers="true">
<ContentTemplate>
<asp:TimerID="Timer1"runat="server"Interval="5000"OnTick="Timer1_Tick"></asp:Timer>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:NautilusDBConnectionString %>"SelectCommand="SELECT [Source], [Loads] FROM [Loads] ORDER BY [IDnum]"CacheDuration="1"></asp:SqlDataSource>

<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataSourceID="SqlDataSource1"Style="z-index: 100; left: 270px; position: absolute; top: 39px"></asp:GridView>

<asp:LabelID="Label1"runat="server"Height="19px"Style="z-index: 102; left: 18px;

position: absolute; top: 186px"

Text="Label"Width="198px"></asp:Label><br/></ContentTemplate></asp:UpdatePanel></form>

</

body>

</

html>

No comments:

Post a Comment