Executing JavaScript function after update panel has updated
Posted on 12/10/2007 9:13:30 AM
in #Atlas
Hi,
Last week I was working on a project and integrating AJAX to some existing code base. I had two small requirements. I wanted to run different JavaScript function once the server side execution is finished.
I had one function which was needed to fire after and or every update panel update, and some other JavaScript function to fire on specific update of update panel.
To execute a JavaScript function after any and every update panel update we can use the following code.
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(foo);
This will make the JavaScript function foo() to fire after every update panel update.
But if you want to call specific JavaScript function after specific update panel update, then this method will not be useful. What we can do is call the JavaScript function from the server side.
This can be done with the help of the static function RegisterStartupScript of the scriptmanager class. The following code needs to be written in the server side for the execution of JavaScript function after a call back. This code should be written in the event which is executed in the callback (button click).
ScriptManager.RegisterStartupScript(this, this.GetType(), "foo", "foo();", true);
Here the code will execute the JavaScript function foo() after the server side execution is complete.
Vikram
|
Posted on 12/17/2006 12:01:35 AM
Firstly, NewId() nevers gives you a number. It is a GUID which is alphanumeric. To get a number only random value, do this:
select checksum(newid()) as 'Unique Column', column2 from tablename
|
Posted on 3/12/2007 1:53:59 AM
i have one table and table consists of many rows approx 5000. so i want to get random data from that table. For Example -if i have 500 rows and i want to fetch 50 rows randomly. So how can i do it. Plz anybody help me.
Thanks
|
Posted on 3/12/2007 7:10:24 PM
Hi Gaurav
The above example should Help.
|
Posted on 1/17/2008 2:57:36 PM
hey, thank you. that was extremely heplful, and very useful for when you need to run different javascript for different steps within a wizard control. thanks again!!
|
Posted on 3/11/2008 11:46:22 AM
This is not working for me; however, my situation is slightly different. From an async postback I I programatically add a UserControl to an update panel. The UserControl has some javascript inside it that needs to run immeditately to hook events and such. The same user control works fine when placed on a page declaratively -- all the JS runs on load. Any idea how I can get this JS to run at the end of the async request?
|
Posted on 4/8/2008 7:04:46 AM
Hey Thanks a lot!! was exactly looking for this..
|
Posted on 4/25/2008 2:46:52 PM
Thank you sooooo much for posting this. I have tried everyway to get this working. Your method finally worked for me....What did we ever do before the internet....Nice work.
|
Posted on 4/29/2008 10:06:06 PM
but does it run always?i think that it is only fired at the first loading of the page but not after a call back.
also my javascript code was dynamic and i use the alert with some dynamic string.
|
Posted on 6/27/2008 6:39:12 AM
how to validate a single textbox with many Regex in MVC and how to implement callback in MVC
|
Posted on 7/30/2008 2:53:31 AM
Hi,
I am calling a function like this,
ScriptManager.RegisterStartupScript(this, this.GetType(), "foo", "foo(a);", true);
but at this line it is throwing error saying that a is undefined which is the parameter I am trying to pass.
a is the anchor element for which I want to make some changes.
Please let me know how to do this. Thank you.
|
Posted on 8/25/2008 8:05:18 AM
lakshmi,
put the a between single quotes....
ScriptManager.RegisterStartupScript(this, this.GetType(), "foo", "foo('a');", true);
:-)
|
Posted on 10/14/2008 9:09:47 AM
Hi, this post where weryyyy useful but can you tell me how to register function to be fired BEFORE request?
Can you help me with this?
|
Posted on 10/14/2008 9:10:21 AM
Hi, this post where weryyyy useful but can you tell me how to register function to be fired BEFORE request?
Can you help me with this?
|
Posted on 2/27/2009 7:00:31 AM
Hi,
In IIS7 i am calling this function in button click event as
ScriptManager.RegisterStartupScript(this, this.GetType(), "Msg", "alert('a');", true);
but the message not displayed.
But if i call the function as
ScriptManager.RegisterStartupScript(ButtonObject,this.GetType(), "Msg", "alert('a');", true);
this line is executed and message is displayed.
For this i have to chage the code in the entire website which is deployed on production server with IIS6.
Is there any way to overcome this problem by modifying web.config file?
|
Posted on 8/31/2009 7:37:58 PM
Appreciate your article, it saved my day!
|
Posted on 3/5/2010 3:49:55 PM
Thanks for you article...
|