0

I have set of jquery files.like this :

 <script src="js/PortalJs/jquery-ui-personalized-1.6rc2.min.js" type="text/javascript"></script> <script src="js/PortalJs/inettuts.js" type="text/javascript"></script> 

How is it possible to call these files after a specific update panel has been loaded.

3
  • What do you mean by "call" exactly, do you want to run some specific JavaScript? Because at least the first entry just loads a library, it shouldn't matter when you do that Commented Feb 15, 2012 at 14:32
  • yes the first one is okay, but after i click on a link button triggered in the updatepanel the effect of the jquery disappeared totally. Commented Feb 15, 2012 at 14:35
  • more info about the real problem is here :stackoverflow.com/questions/9292547/… Commented Feb 15, 2012 at 14:35

4 Answers 4

3

To make calls on javascript side after the update panel loaded you use this standard code.

var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_initializeRequest(InitializeRequest); prm.add_endRequest(EndRequest); function InitializeRequest(sender, args) { } function EndRequest(sender, args) { // here you can load your scripts. } 

You can add at the EndRequest a code that loads the javascript, but take care to load it only ones. If the jQuery have conflicts try the jQuery.noConflict() command. http://api.jquery.com/jQuery.noConflict/

Sign up to request clarification or add additional context in comments.

3 Comments

@just_name You write this code in the page on javascript session, and this is trigger when any update panel is updated. You can use to load your script after the update panel loaded.
How can I load my script then? append it to <head> tag ?
@Nexus Yes, you can place it there... or also on the bottom of the page, make sure that is loaded on pageload
2

Sys.WebForms.PageRequestManager endRequest Event

MSDN Documentation The endRequest event is raised after an asynchronous postback is finished and control has been returned to the browser. You can use this event to provide a notification to users or to log errors.


Reference - endRequest


Sample Code

<script type="text/javascript" language="javascript"> function EndRequestHandler(sender, args){ // here you can call the function provided by other user } <script 

So you will have to write down the script loading function in javascript...

Comments

2

Here is a function that I use to add dependencies dynamically

function addDependencies(args) { var head = document.getElementsByTagName('head')[0]; // todo refactor this logic function exists(tag, src) { var elms = document.getElementsByTagName(tag); for (var i=0; i<elms.length; i++) { if (elms[i].getAttribute('src') === src) { return true; } } } for (var src in args) { var isCss = /.+\.css$/i.test(src); var isJs = /.+\.js$/i.test(src); var tag = isCss ? 'link' : 'script'; if (!exists(tag, src)) { if (isCss) { if (document.createStyleSheet) { document.createStyleSheet(src); } else { var link = document.createElement(tag); link.type = 'text/css'; link.href = src; head.appendChild(link); } } else if (isJs) { var script = document.createElement(tag); script.type = 'text/javascript'; script.src = src; script.onload = args[src](); head.appendChild(script); } } } } 

heres a demo

Comments

1

update panel has an onLoad event: http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.onload.aspx.

<asp:UpdatePanel OnLoad="upOnload" ... 

you can load your javascript from the updatePanel Onload event in code behind like this:

 protected void upOnload(object sender, EventArgs e) { Page.Header.Controls.Add(new LiteralControl("<script type='text/javascript' src='" + Page.ResolveUrl("~/js/PortalJs/inettuts.js") + "'></script>")); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.