Rectangle 27 8

I fiddled around with the ScriptManager suggestions - which I reckon I would have eventually got working but it seems to me that the Timer idea is easier to implement and not really(!) that much of a hack?!

Here's how I got my panel updated after the initial page render was complete...

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAXPostLoadCall._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <h2>And now for a magic trick...</h2>
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True">
        </asp:ScriptManager>
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick" />
                    <asp:Label ID="Label1" runat="server">Something magic is about to happen...</asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>

        </div>
    </form>
</body>
</html>

and the code behind default.aspx.cs reads

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace AJAXPostLoadCall
{
    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void DoMagic()
        {
            Label1.Text = "Abracadabra";
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            // Do the magic, then disable the timer
            DoMagic();
            Timer1.Enabled = false;
        }

    }
}

So, the page loads up and the Timer (contained within the UpdatePanel) fires 2 secs after the page has loaded up (I think - I'm not sure when the Timer actually starts?). The label text is rewritten and then the Timer is disabled to stop any more updates.

Simple enough - but can you purists out there tell me if this is a Horrible Hack?

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 2

The idea is that you register a script to run on start up (I believe once the page has loaded). Your script should call a function that causes a post back through your UpdatePanel

This is a better correct answer. Thanks Tom, for pointing me in the right direction. Extended answer here: stackoverflow.com/questions/3877951/

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 1

Doing things like this with UpdatePanels rather than something easily understandable WILL bite you, it's just a matter of when.

I think UpdatePanels are easily understandable! Are you taking issue with the timer idea or with the whole notion of ASP UpdatePanels? What biting do I need to be aware of? Thanks....

@Sal: Do you know what's happening behind the scenes? Including the page lifecycle? How is the viewstate propagated to the page viewstate? Why does this fail with nested UpdatePanels unless Framework 3.5 SP1 is installed on the web server?

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 1

Use a timer control that will be fired after a certain number of milliseconds (for page to load). In the timer tick event refresh the update panel.

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 1

From the very first question on this post, I think what the user is looking for is a message to be displayed to the user while the update panel loads. Just put an UpdateProgress control like the one below on your page just above your UpdatePanel control, and feel free to trigger an event in your UpdatePanel, put your backend code as usual, and whatever is contained inside the UpdateProgress control will load up while your UpdatePanel content is being processed in the backend.

<asp:UpdateProgress AssociatedUpdatePanelID="UpdatePanel1" ID="UpdateProgress1" runat="server">
  <ProgressTemplate>
    <div class="mystyleclass">
      Please Wait...
    </div>
  </ProgressTemplate>
</asp:UpdateProgress>

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 2

It's most likely due to the fact that the page update is happening through the update panel. Startup scripts can have issues with not firing in these cases, and need to be wrapped in:

Sys.Application.add_load(function(){ myFunctionCall(); });

It's the Microsoft AJAX library's way of ensuring your startup script happens when it should during MS AJAX roundtrips.

Here's an easy way to ensure all client scripts added to the page work, regardless of whether they are contained in an ajax updatepanel or not. We use this in all of our projects and it works flawlessly:

i snagged the function from your other answer - upon partial postback of the update panel it appears to be calling the initializeControl function twice - any thoughts?

scriptText = String.Concat("Sys.Application.add_load(function(){", scriptText, "});")

@jbabey good stuff. Yes my answer here is if you were simply going to use it in isolation. The linked question/answer is a complete solution that doesn't require you to add the add_load call because the code does it for you.

asp.net - Injecting javascript from a user control inside an UpdatePan...

javascript asp.net vb.net user-controls updatepanel
Rectangle 27 2

It's most likely due to the fact that the page update is happening through the update panel. Startup scripts can have issues with not firing in these cases, and need to be wrapped in:

Sys.Application.add_load(function(){ myFunctionCall(); });

It's the Microsoft AJAX library's way of ensuring your startup script happens when it should during MS AJAX roundtrips.

Here's an easy way to ensure all client scripts added to the page work, regardless of whether they are contained in an ajax updatepanel or not. We use this in all of our projects and it works flawlessly:

i snagged the function from your other answer - upon partial postback of the update panel it appears to be calling the initializeControl function twice - any thoughts?

scriptText = String.Concat("Sys.Application.add_load(function(){", scriptText, "});")

@jbabey good stuff. Yes my answer here is if you were simply going to use it in isolation. The linked question/answer is a complete solution that doesn't require you to add the add_load call because the code does it for you.

asp.net - Injecting javascript from a user control inside an UpdatePan...

javascript asp.net vb.net user-controls updatepanel
Rectangle 27 0

Doing things like this with UpdatePanels rather than something easily understandable WILL bite you, it's just a matter of when.

I think UpdatePanels are easily understandable! Are you taking issue with the timer idea or with the whole notion of ASP UpdatePanels? What biting do I need to be aware of? Thanks....

@Sal: Do you know what's happening behind the scenes? Including the page lifecycle? How is the viewstate propagated to the page viewstate? Why does this fail with nested UpdatePanels unless Framework 3.5 SP1 is installed on the web server?

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 0

A thumbs-up and thanks to SAL and the rest of you guys. This solved a big issue I had, my procedure was taking up to a minute for the page to finally render and display.

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 0

I would agree with some of the other posters here. IE, Chrome, and FF seem to handle server-side controls with both client-side and server-side events handlers differently. It has been my experience that sometimes they wait for the client JavaScript to end, then perform the post-back to handle the server-side...but this isn't always the case.

The solution I always turn to:

Go ahead and set the onChange() event on your DropDownList only...then in your JavaScript, manually force the postback using something like the

syntax to make your page use that control for the postback. In your server-side code you can just query the current index value off the DropDownList, and perform whatever processing you want...the UpdatePanel should handle this situation perfectly...

I've had probably the same issue.. It was soo strange Firefox wouldn't fire a postback on 2 of my dev computers but on a third it was fine (this was on a linkbutton).. It mean't we had to move to IE for demo purposes.. I will try fdfrye's suggestion.. It looks very plausible

javascript - ASP.NET DropDown SelectedIndexChanged not firing in Firef...

asp.net javascript ajax firefox updatepanel
Rectangle 27 0

Feel free to correct me as this was my solution a very very long time ago:

We hit this and the only way we ended up being able to do it was to attach an event to the id of the dropdown itself and access it via document.getElementById (easy enough to find the id with a view source :)

Lame answer with a lame solution but that's how we got around the issue a few years back. Would be interested if anyone actually knows how to fix it :)

javascript - ASP.NET DropDown SelectedIndexChanged not firing in Firef...

asp.net javascript ajax firefox updatepanel
Rectangle 27 0

found out the you have to inherit your control from IPostBackDataHandler, also, the asynchronous problem is there. I have used a workaround, I have put the control in updatepanel (put updatepanel on aspx), registered a button through control onclick of which is bound, on jquery/javascript I am firing the click event of the button to send the calls asynchronously. Things work fine, but after firing that event javascript code doesnt run again, tried calling the function by registering client script in prerender again, didnt work.

c# - Buttons on click event, inside an update panel, rendered through ...

c# custom-controls asp.net-customcontrol
Rectangle 27 0

The ScriptManager.RegisterStartupScript allows a script to run on startup inside of an update panel. if you use the old ClientScript.RegisterStartupScript then the script you render will be outside the bounds of the udpate panel, and thus won't be executed during async page loads.

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 0

I fiddled around with the ScriptManager suggestions - which I reckon I would have eventually got working but it seems to me that the Timer idea is easier to implement and not really(!) that much of a hack?!

Here's how I got my panel updated after the initial page render was complete...

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAXPostLoadCall._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <h2>And now for a magic trick...</h2>
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True">
        </asp:ScriptManager>
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick" />
                    <asp:Label ID="Label1" runat="server">Something magic is about to happen...</asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>

        </div>
    </form>
</body>
</html>

and the code behind default.aspx.cs reads

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace AJAXPostLoadCall
{
    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void DoMagic()
        {
            Label1.Text = "Abracadabra";
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            // Do the magic, then disable the timer
            DoMagic();
            Timer1.Enabled = false;
        }

    }
}

So, the page loads up and the Timer (contained within the UpdatePanel) fires 2 secs after the page has loaded up (I think - I'm not sure when the Timer actually starts?). The label text is rewritten and then the Timer is disabled to stop any more updates.

Simple enough - but can you purists out there tell me if this is a Horrible Hack?

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 0

Something that I have noticed is that the SelectedIndexChanged event will not fire unless the value has been changed. So if your DropDownList's ListItems do not have unique values, just add a random number to make it unique.

javascript - ASP.NET DropDown SelectedIndexChanged not firing in Firef...

asp.net javascript ajax firefox updatepanel
Rectangle 27 0

A thumbs-up and thanks to SAL and the rest of you guys. This solved a big issue I had, my procedure was taking up to a minute for the page to finally render and display.

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 0

I'm pretty sure that you have some problems in client side since There has been similar reports. Use firebug to track the js error. have a look at http://www.webmasterworld.com/profilev4.cgi?action=view&member=Nazgoth about ochange event in firefox. If you can't find the source of your problem, post your js here.

javascript - ASP.NET DropDown SelectedIndexChanged not firing in Firef...

asp.net javascript ajax firefox updatepanel
Rectangle 27 0

The idea is that you register a script to run on start up (I believe once the page has loaded). Your script should call a function that causes a post back through your UpdatePanel

This is a better correct answer. Thanks Tom, for pointing me in the right direction. Extended answer here: stackoverflow.com/questions/3877951/

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax
Rectangle 27 0

From the very first question on this post, I think what the user is looking for is a message to be displayed to the user while the update panel loads. Just put an UpdateProgress control like the one below on your page just above your UpdatePanel control, and feel free to trigger an event in your UpdatePanel, put your backend code as usual, and whatever is contained inside the UpdateProgress control will load up while your UpdatePanel content is being processed in the backend.

<asp:UpdateProgress AssociatedUpdatePanelID="UpdatePanel1" ID="UpdateProgress1" runat="server">
  <ProgressTemplate>
    <div class="mystyleclass">
      Please Wait...
    </div>
  </ProgressTemplate>
</asp:UpdateProgress>

javascript - ASP.NET AJAX: Firing an UpdatePanel after the page load i...

asp.net javascript asp.net-ajax