Showing posts with label Ajax. Show all posts
Showing posts with label Ajax. Show all posts

Tuesday, 9 August 2011

RegisterStartupScript vs RegisterClientScriptBlock


I have a site with loads of pages with Ajax tabbed containers on them. Generally each tabbed container is contained within an Update Panel. Some have additional Update Panels on the tabs.

Whenever a user clicks an Update button, I go back to the server, check if they have permission to do the action they are doing and, if they don't return to the page and EITHER do this:



I find, on various pages, one works and the other does not. If I'm using RegisterClientScriptBlock and the alert does not show, I change it to RegisterStartupScript - and it works - the alert shows.

But the reverse can also be true. Sometimes RegisterStartupScript does not work, and if I change it to RegisterClientScriptBlock it works.

I have checked this out in detail on different pages - where the code is pretty much identical i.e. there is an Update Panel containing a tabbed container and nothing else. Sometimes I have to use RegisterStartupScript - sometimes I have to use RegisterClientScriptBlock.

RegisterClientScriptBlock -> Put a function or a block of code (javascript) on the page which you may not want executed immediately.

RegisterStartupScript -> Put some code on the page which you want executed as soon as the page finishes loading.


Tuesday, 28 June 2011

Update Panel Mode in Ajax

Here is the interesting point to Discuss with you about the Update Panel Mod. Hope Everybody Likes this.
  
There are two Mode of Update panel in Ajax. 







    Mode="Conditional' causes the updatepanel to update when one of three things happen:

    1) If a Control within the Update panel causes the actual Post back
    2) If a Trigger on the Update panel updates
    3) If someone calls "Update()" on the Update panel itself
    Otherwise, it won't update and refresh.  When it is set to always, however, it will always refresh.