jQuery(document).ready() load() aspx - asp.net

I am using jQuery 1.3.1 and saying $('#somediv').load('somepage.aspx') An aspx that have a Repeater which loads few images. When loading is complete a cycle() function (jQuery plug-in) will be called upon them.
Now I have this working on http://www.techlipse.net/test/agb via the function called from the menu-event-handlers (a combo box). When it is loaded via the event handler of the combobox I call cycle() plugin as a callback function to the load() method, or function .. I think I might have misunderstood some of the fundemantals of javascript, or why the document.ready() is firing long before the images are fully loaded therefore failing the cycle() plug in. When it is said to be a bug of jQuery1.3.1 that it does wait for them to load. Posted here:
JQuery is waiting for images to load before executing document.ready
any help .?

document.ready fires once the document is ready. Not the images. You'll have to run a second check on images to check they have totally loaded.

The whole point of $(document).ready is that it fires as soon as the DOM is manipulable, but before window.onload - which fires after all HTTP traffic is done with.

You should upgrade from 1.3.1 ASAP. Its $(document).ready() functionality was buggy, making generally correct answers about $(document).ready() not necessarily accurate in your situation.

Related

UpdatePanel Conditional updatemode not working

I found this thread while trying to resolve my issue unfortunately this I can't seem to figure out the problem since I already have everything the way it should be.
I've got 3 updatepanels that each call a function on a .js file setup like this:
<asp:UpdatePanel ID="upPnlGeneralinfo" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<script type="text/javascript">
Sys.Application.add_load(BindPageLoad);
</script>
Each have a different ID of course. Whenever a control calls a postback within the update panel it works, however in the js file I added a console.log("running the js file") and I can see that it's being called three times meaning it's all three updatepanels are being refreshed instead of just the one.
All the triggers are inside each of the respective updatepanels so I shouldn't need to add any triggers (I did just to make sure and it makes no difference). Shouldn't the UpdateMode=Conditional resolve this?
Also worthy to mention, none of my code behind ever calls any updatepanel.update(). I tried adding that for each control to their respective panels and that also made no difference.
Any ideas?
It doesn't necessarily mean all your update panels are being refreshed.
The MSDN docs say the client load events are raised after either a synchronous (full page postback) or asynchronous (partial page) postback.
This might mean that only one of your update panels is refreshing as intended, but all three event handlers are run again after the async postback because of how they were hooked up using MS Ajax.
MSDN excerpt:
Client Events of the Application and PageRequestManager Classes
Sys.Application.load Event
Sys.Application.add_load(handler);
Raised after all scripts have been
loaded and all objects in the
application that are created by using
$create are initialized. The load
event is raised for all postbacks to
the server, which includes
asynchronous postbacks.
-- http://msdn.microsoft.com/en-us/library/bb386417.aspx
Working with Partial-Page Rendering Events states a different event that runs only when the entire page loads:
During ordinary page processing in the
browser, the window.onload DOM event
is raised when the page first loads
-- http://msdn.microsoft.com/en-us/library/bb398976.aspx
This the regular DOM load method, not part of MS Ajax.
Therefore I assume if you hook your client code to the regular window.onload event then it will run only when the full page loads, on the first time, not on successive async postbacks (aka update panel/partial refresh).
Whether or not this knowledge is harnessable to provide the outcome you want I'm unsure. Maybe you're looking at only the MS Ajax objects for a solution when a hybrid browser/MS Ajax client solution exists.

asp.net postback with jquery ajax and jquery dialog

We have a method on an asp.net page that is called on a button click. The problem is that the method take a long time to process. I've been asked to have the page call the method (or call the postback) and then display the jquery.ui dialog which will let the user know that this process could take a long time. I'm looking at serializing the asp.net form and doing a $.post() but to be honest I'm completely stuck on whether this will even work and how I can prevent the actual postback from happening and just displaying the dialog. Has anyone had any experience with doing this that can give me some pointers?
I found this http://dotnet.dzone.com/news/eliminating-postbacks-setting- but I'm not sure if it's a bit OTT. The article is a little long winded.
Hope someone can help.
That would be easier if you can use an UpdatePanel (which basically boils down to ASP.NET's way of doing what you're considering with the $.post(), but automatically gets the ASP.NET specific stuff right).
Then, you can do something simple like this: http://encosia.com/2008/10/04/using-jquery-to-enhance-aspnet-ajax-progress-indication/
You can send a post request through javascript (AJAX) without using asp.net's ajax framework. So in other words do it manually. Ajax would be perfect in this case, because you are trying to show loading indicators on the front-end while you are waiting for a response from the server.
To do this, take the logic out of your button_click method and put it in a separate page (text.aspx see below). Then you can call that page like this (using JQuery):
$('#ProgressIndicator').show();
$.post("test.aspx", function(data){
alert("Data Loaded: " + data);
$('#ProgressIndicator').hide();
});
If you can't use JQuery in your project, see: AJAX

How call function jquery in the event inserted of a formview

Is it possible to call the inserted event of formview in asp.net? from jQuery for example:
$ ('#FormView1').Inserted (function () (/ / code ....
how do it???
Not really.
FormView is a server-side object with server-side events - they are written in C# (or other .net language), and run on your server.
jQuery is a JavaScript framework - it runs on people's browsers.
It is possible to expose the functionality to AJAX calls as long as you're only updating the database. If the ItemInserted event is changing the page in any way, you'll have to rewrite it in jQuery. You will also experience problems with the ViewState once you do post the page back, so you may want to disable it (or your data will appear outdated when you post back). Either way, it isn't a quick fix as you might expected. Sorry.

Javascript object not initialized on slow connections

Here's the odd situation:
we have a piece of javascript library that is being called on our onload of aspx page.
It works everytime for us, but the clients that have low speed modems get an error, because the object is not getting initialized and the aspx page is already loaded.!!
Is there any suggestions on how to call this piece of js code?
Thanks,
make sure you have your end tags.. i have seen onLoads in the not working right when your core tags are incomplete or not properly formatted
The onload even happens when everything in the page is loaded. If you have some script that is loading from a different server (ads, statistics), the onload event won't fire until those are loaded also. If their server is having problems, your onload may never fire at all, or after several minutes when the browser gives up waiting.
Instead of using onload you could put your code in a script tag as early as possible in the page, i.e. after the last element that the script needs.
If you have some external script that doesn't need a specific place in the page (statistics for example), you can move it to the bottom of the page to minimise the risk of interference with the rest of the page.
With JQuery you can call your functions with ready event :
$(document).ready(function() {
// call your functions here
});
The event will be called when the DOM is loaded.

In my ASP.NET app, registering a script from code-behind before a page has loaded throws an "operation aborted" error in IE

I understand that in IE 5.5, 6, and 7, when you modify a DOM element before it is 'closed', it throws an "operation aborted" error (this article has more information: http://www.clientcide.com/code-snippets/manipulating-the-dom/ie-and-operation-aborted/)
In my ASP.Net application, I am registering a client script block on the page during the page_load event. (I tried moving this code to the page_loadcomplete event or page_prerender event with no luck).
Here is my code (pretty basic):
// Checks if the handler is a Page and that the script isn't already on the Page
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("blockUIAlert"))
{
ScriptManager.RegisterClientScriptBlock(page, typeof(ScriptUtilities),
"blockUIAlert", script, true);
}
I'm using this same code from other AJAX postbacks in my page without a problem. This error only occurs if this code is called when the page is being loaded.
What can I do to have this code be called after the DOM elements are closed? I don't want the user to have to initiate this action manually -- I want this code to be executed as soon as the page is loaded, provided certain server-side conditions are met.
If you are using YUI, or jQuery they have js event listening functions that will run code when the DOM is done loading. I am betting that MS Ajax library has a similar function.
jQuery Examples
Maybe this is the answer you're looking for.
I was having the operation aborted error and like you I also knew why it happens, but I was 100% certain that I was not modifying a DOM element before it was 'closed'. Turns out the bug was in the ASP.NET AJAX client-side framework. I had to modify the client-side framework. Please see the question I posted, Internet Explorer's Operation Aborted and Latency Issue
I also just noticed that your are using RegisterClientScriptBlock. Try ScriptManager.RegisterStartupScript(...).
I use the page_load event for this same purpose.
What event you attach the script on the server-side does not matter. Your problem is purely client-side and you did not provide any script. However I guess calling the function on the onload event might work. For example <body onload='yourFunction()'>

Resources