Showing posts with label released. Show all posts
Showing posts with label released. Show all posts

Saturday, March 24, 2012

AJAX Timer not Ticking in MasterPages

Hi,

I have a timer control of the new AJAX version released. When in a page that doesn't have any MasterPages the Timer works perfectly, however when you give a MasterPage to the Page the Timer never Ticks!!!... I put a ScriptManagerProxy in the aspx page and a ScriptManager in the MasterPage (followed exactly the example on this site), but still to no avail.

why is this ? is this a bug ? am I missing something else ? anyone encountered something the sort?

Thanks!

Can you post some code which doesn't work? What is a purpose of the ScriptManagerProxy? I wrote a simple example for Timer and master page and I didn't find any problems.

<%@. Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" runat="server" Interval="5000">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="Load_Some_Data" UpdateMode="Conditional">
<triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</triggers>
<contenttemplate>
<p>Refresh number: <asp:Literal ID="lit1" runat="server">0</asp:Literal></p>
</contenttemplate>
</asp:UpdatePanel>
</asp:Content>

public partial class Default2 : System.Web.UI.Page
{
protected void Load_Some_Data(object sender, EventArgs e)
{
lit1.Text = GetSomeNumber();
}
private string GetSomeNumber()
{
int i;
if (!int.TryParse(lit1.Text, out i))
return "ERROR";
else
return (++i).ToString();
}
}


Hello and thanks for the reply..

Try this: the Timer has to start Disabled and Enable it at runtime by a click event or so... also I'm seeing you don't have a Tick event!?


Here is a solution when Timer is by default disabled and during runtime enabled. I don't have tick event because updatepanel is refreshed every 5 seconds and on every refresh method Load_Some_Data is executed. What are you doing in your tick event and it can't be done this way?

<%@. Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" runat="server" Interval="5000" Enabled="false">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="Load_Some_Data" UpdateMode="Conditional">
<triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</triggers>
<contenttemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<p>Refresh number: <asp:Literal ID="lit1" runat="server">0</asp:Literal></p>
</contenttemplate>
</asp:UpdatePanel>

<asp:Button ID="Button1" runat="server" Text="Enable Timer" OnClick="Button1_Click" />
</asp:Content>

public partial class Default3 : System.Web.UI.Page
{
protected void Load_Some_Data(object sender, EventArgs e)
{
lit1.Text = GetSomeNumber();
TextBox1.Text = lit1.Text;
}
private string GetSomeNumber()
{
int i;
if (!int.TryParse(lit1.Text, out i))
return "ERROR";
else
return (++i).ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
Timer1.Enabled = true;
}
}


hey thanks bsebo for following my case...

currently I don't have my code in front have to get home. 3hrs more :\....

basically the situation is this: A ScriptManager in the MasterPage, ScriptManagerProxy in the Page. A disabled Timer on the Page and on Button click event is gets Enabled. Ok it gets "Enabled" BUT the Tick Event is never executed.. .while without a MasterPage it gets executed. I need to work with the Tick event as I'm doing some process on the Tick event and thats it! ... I will post the code when I get back home.

Thanks again!


<%

@.PageLanguage="C#"MasterPageFile="~/MasterPage.master"AutoEventWireup="true"CodeFile="Default2.aspx.cs"Inherits="Default2"Title="Untitled Page" %>

<

asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server"><asp:ScriptManagerid="ScriptManager1"runat="server"></asp:ScriptManager><asp:UpdatePanelid="UpdatePanel1"runat="server"><contenttemplate>

<

asp:Buttonid="Button1"onclick="Button1_Click"runat="server"Text="Start"></asp:Button><asp:Labelid="Label1"runat="server"Text="Label"></asp:Label>

</

contenttemplate><triggers>

<

asp:AsyncPostBackTriggerControlID="Timer1"EventName="Tick"></asp:AsyncPostBackTrigger>

</

triggers></asp:UpdatePanel><asp:Timerid="Timer1"runat="server"Enabled="False"Interval="5000"OnTick="Timer1_Tick"></asp:Timer>

</

asp:Content>

public

partialclassDefault2 : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedvoid Button1_Click(object sender,EventArgs e)

{

Timer1.Enabled =

true;

Label1.Text =

"Timer started";

}

protectedvoid Timer1_Tick(object sender,EventArgs e)

{

Timer1.Enabled =

false;

Label1.Text =

"Timer stopped";

}

}

Hi, I'm back, managed to post the code... as you can see the Page has a MasterPage. ... while this peace of code works in a Page without a MasterPage...with a MasterPage it would start (or seem to be Enabled) but would never Tick. This is a bug for sure.... I'm testing right now with many possibilities but neither would work..

In fact something really weird and shows more that this is a BUG... is that when on debug the Timer is set to Enabled it will start Ticking but not when started from a Button.

bsebo you have to provide an example similar to what I said... thanks but yours is not what I want... bsebo try doing it with a Tick event ;)... your not using the Timer properly.

Thanks! martin


You right, it doesn't work. If you put the Button1 outside of the UpdatePanel1 then it can enable the Timer1. But, if you put it inside of the UpdatePanel1 then it can't. It seems like a bug because when you look at a:

<script type="text/javascript">
<!--
Sys.Application.add_init(function() {
$create(Sys.UI._Timer, {"enabled":false,"interval":5000}, null, null, $get('ctl00$ContentPlaceHolder1$Timer1'));
});
// -->
 enabled is always set to false.

</script>


It doesn't work yes... but are you sure because of that? I tried on a Page without a MasterPage and viewed the source while a Timer1 was enabled... it still showed that it was "enabled":false.

There's sure a bug... I hope some from the ASP team reads this!

I cannot quite get a grasp on what's happening.. why should a MasterPage conflict that much?

Thanks!


Hello so is there any work arounds?... or have to wait for the fix?

AJAX Timeouts & Issues

Last week we released the AJAX version of one of our sites to the general public. We had QA tested the site pretty well including the end users to make sure we didn't run into any issues with the new AJAX functionality. The site is using basic AJAX, that is, we are using update panels to mainly improve the user experience.

Most of the users are not having any problems at all, but a small number are reporting script manager timeouts and others are getting the 12031 error. Both of these issues apprear to be pretty random, but they are repeatable outside our network. The calls that are getting the timeouts should be sub-second but once the call is made, ends up taking more than the default 90 seconds and the default error handling in the AJAX clients scripts gives a simple error popup. We don't see any server errors at all. I have even replicated what the user is doing at the same time and don't see any slow downs or delays.

Any ideas? Are we missing some configuration, firewall settings?

Thanks, Pat

Ok, we have narrowed down our issue. It seems our Cisco load balancer seems to be configure incorrectly or old version of firmware or something. If we bypass the load balancing, the site works fine. We still don't know why only a small number of people have this issue with the AJAX calls and most of the other don't. I will update this post as I find out more..


Did you find out any more about this?

My boss went to a client demo and was greeted with error messages when clicking any buttons that are inside a page with AJAX applied. The pages initially load fine, it's only on button clicks.

Like you posted, it works fine on our network, home networks and other corporate networks, but our client's network seems to handle things differently.

He even ran the demo on his own laptop which uses the site fine when he's in his own office.

The popup error we get is;

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status cod returned from the server was : 12031


Been a while, but I figured that I would respond with some of the issue we ran into when deploying AJAX to the public. The majority of our users are internal, but we have about 1/3 of our users that are external and are all over the world...

"Access is denied" error when running AJAX page inside a iframe - this is a known issue and there is a "hack" to get it to work, but MS said that we will have to wait for .Net 3.5 for a real fix.


Oops, forgot the one that this post started with. We are using Cisco's CSS load balancer and the way our load balanced was designed was also causing not only too much traffic on our network, but also causing issues with AJAX. Our networking guy redesigned and all our issues went away. The old design was pretty strange and not recommended by Cisco, the new design is pretty standard.