Hi !
I Included the "EvalScripts.js" .
But it is giving the following javascript error at
function js_registerJsEval()
{
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(js_beginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(js_pageLoadedHandler);
}
"
--------
Error
--------
A Runtime Error has occurred.
Do you wish to Debug?
Line: 59
Error: 'Sys' is undefined
--------
Yes No
--------
Do i need to include any other tags ?
Currently i included the following code
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" />
<atlas:UpdatePanel ID="up1" runat="server" OnLoad="up1_Load" >
<ContentTemplate>
<table>
...
...
<tr>
<td>
<asp:Button ID="saveBtn" runat="server" Text="Save" ToolTip="Save Information To DataBase" OnClick="OnSaveClick" />
</td>
</tr>
</table>
</ContentTemplate>
</atlas:UpdatePanel>
In the onSaveclick() i am registering a Startup Java Script like
ClientScript.RegisterStartupScript(
typeof(HR_HINHrmDomicillaryTreatmentClaimForm),"round","alert('Saved Successfully');",true);Please guide me further.
hello.
sorry, but i'm not following: what do you mean by updatepanels not evaluating javascript statements? if you need to insert or run jscript instructions after a partial postback, you should use the static registerXXX methods of the scriptmanager class.
Luis Abreu:
hello.
sorry, but i'm not following: what do you mean by updatepanels not evaluating javascript statements? if you need to insert or run jscript instructions after a partial postback, you should use the static registerXXX methods of the scriptmanager class.
Can you please give an example of how to do this?
I have custom control that is now within an UpdatePanel and none of the JavaScript that it registers with thePage.ClientScript.RegisterXYZ methods is getting loaded.
Thanks!
It not Atlas compatible.
Upgrade your Atlas to new ASP.AJAX.
Luis Abreu:
hello.
sorry, but i'm not following: what do you mean by updatepanels not evaluating javascript statements? if you need to insert or run jscript instructions after a partial postback, you should use the static registerXXX methods of the scriptmanager class.
I can use RegisterXXX methods, but many of third-party controls (for example telerik controls) not using this methods, and simply don't work together with ASP.NET AJAX.
Btw, now I develop new library (base Page class) that on Render method detects javascripts and register them via RegisterXXX methods.
lgoodell:
Luis Abreu:
hello.sorry, but i'm not following: what do you mean by updatepanels not evaluating javascript statements? if you need to insert or run jscript instructions after a partial postback, you should use the static registerXXX methods of the scriptmanager class.
Can you please give an example of how to do this?
I have custom control that is now within an UpdatePanel and none of the JavaScript that it registers with thePage.ClientScript.RegisterXYZ methods is getting loaded.
You have some control in UpdatePanel and you want register some scripts in partial update?
1<asp:UpdatePanel runat="server" ID="ThePanel" UpdateMode="Conditional">2 <asp:Label runat="server" ID="TheLabel" />3</asp:UpdatePanel>and code behind:
1protected void InjectScript()2{3 ScriptManager.RegisterClientScriptBlock(TheLabel,typeof(Label),"TestBlock","alert('test')",true);4}this works.ORyou may use my script
I almust forgot about new version.
/*eval scripts (c) restorer'2006some ideas taken from:* protorype library* http://cain.supersized.org/archives/2-Dynamic-loading-of-external-JavaScript-.js-files.html* http://www.scss.com.au/family/andrew/webdesign/xmlhttprequest/*/if (typeof(js_eval_scripts_included) != 'undefined'){js_eval_scripts_included = true;alert('Secondary include.');}var js_ScriptFragment = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';var js_ScriptSrcFragment = '<script.+(src[ ]*=[ ]*\'(.*?)\'|src[ ]*=[ ]*"(.*?)").+';function js_extractScripts(str){var matchAll = new RegExp(js_ScriptFragment, 'img');var matchOne = new RegExp(js_ScriptFragment, 'im');var matchSrc = new RegExp(js_ScriptSrcFragment, 'im');var arr = str.match(matchAll) || [];var res = [];for (var i = 0; i < arr.length; i++){var srcMt = arr[i].match(matchSrc);if (srcMt){if (srcMt.length > 3) res.push(['src', srcMt[3]]);else res.push(['src', srcMt[2]]);}var mtCode = arr[i].match(matchOne) || ['', ''];if (mtCode[1] != '') res.push(['code', mtCode[1]]);}return res;}/*Load script and wait until it loads.(if appent script element to DOM, Firefox does not wait until loading was completed)*/function js_loadScript(src){var ex;var req = null;if (window.XMLHttpRequest){req = new XMLHttpRequest();}elseif (window.ActiveXObject){var msxmls = ['Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];for (var i = 0; i < msxmls.length; i++){try{req = new ActiveXObject(msxmls[i]);break;}catch (ex) {}}}if (req===null || req===false){alert('Unable find XMLHttpRequest or it ActiveX alalog.');return;}req.open("GET", src, false);// not asynchronousreq.send(null);if (req.status == 200){window.eval(req.responseText);}else alert('Unable to load ' + src + ' (' + req.status + ')');}function js_evalScripts(str){var ex;var arr = js_extractScripts(str);for (var i = 0; i < arr.length; i++){switch (arr[i][0]){case 'src':js_loadScript(arr[i][1]);break;case 'code':var cnt = arr[i][1];// hack for RadTabStrip// but the best way is set HttpContext.Current.Request["httprequest"] to true in code behindcnt = cnt.replace(/AppendStyleSheet\(false,/g, 'AppendStyleSheet(true,');eval(cnt);break;}}}function js_updateElement(element){var content = element.innerHTML;setTimeout(function() {js_evalScripts(content)}, 1);}var js_postbackElement;function js_beginRequestHandler(sender, args){js_postbackElement = args.get_postBackElement();}function js_pageLoadedHandler(sender, args){if (typeof(js_postbackElement) === "undefined") return;var updatedPanels = args.get_panelsUpdated();for (var i = 0; i < updatedPanels.length; i++) js_updateElement(updatedPanels[i]);}function js_registerJsEval(){var ex;// don't display error if EnablePartialRendering is falsetry{Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(js_beginRequestHandler);Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(js_pageLoadedHandler);}catch (ex) {}}
I think this is last javascript-based version.
This worked once I figured out the correct name space for ScriptManger which isMicrosoft.Web.UI.
Thanks!
Hmm... It's like that only I using third-party controls that don't work in UpdatePanel
(all others write all controls itself and use ScriptManager.RegisterXXX for it)
But I still think that my work will be useful for others...
So, script name is "evalscripts.js".
Before using you must delete first line (<script ... >) and last (</script>). I testing coloring on this forum :)
1<script type="text/javascript">2/*3Eval scripts after UpdatePanel updates4Copyright (C) 2006 Slavik Tretyak56This library is free software; you can redistribute it and/or7modify it under the terms of the GNU Lesser General Public8License as published by the Free Software Foundation; either9version 2.1 of the License, or (at your option) any later version.1011This library is distributed in the hope that it will be useful,12but WITHOUT ANY WARRANTY; without even the implied warranty of13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14Lesser General Public License for more details.1516You should have received a copy of the GNU Lesser General Public17License along with this library; if not, write to the Free Software18Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA1920some ideas taken from:21* protorype library22* http://cain.supersized.org/archives/2-Dynamic-loading-of-external-JavaScript-.js-files.html23* http://www.scss.com.au/family/andrew/webdesign/xmlhttprequest/24*/2526if (typeof(js_eval_scripts_included) != 'undefined')27{28alert('Secondary include.');29}3031var js_eval_scripts_included = true;3233var js_ScriptFragment = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';34var js_ScriptSrcFragment = '<script.+(src[ ]*=[ ]*\'(.*?)\'|src[ ]*=[ ]*"(.*?)").+';35var js_FunctionNameFragment ='[\\s;\n]*function[\\s\n]*([a-zA-Z_\\$]+[0-9a-zA-A_\\$]*)[\\s\n]*\\(';3637function js_extractScripts(str)38{39var matchAll = new RegExp(js_ScriptFragment, 'img');40var matchOne = new RegExp(js_ScriptFragment, 'im');41var matchSrc = new RegExp(js_ScriptSrcFragment, 'im');4243var arr = str.match(matchAll) || [];44var res = [];4546for (var i = 0; i < arr.length; i++)47{48var srcMt = arr[i].match(matchSrc);49if (srcMt)50{51if (srcMt.length > 3) res.push(['src', srcMt[3]]);52else res.push(['src', srcMt[2]]);53}5455var mtCode = arr[i].match(matchOne) || ['', ''];56if (mtCode[1] != '') res.push(['code', mtCode[1]]);57}5859return res;60}6162/*63Eval string and register functions in global namespace64*/65function js_EvalString(str)66{67/*68in "http://cain.supersized.org/archives/2-Dynamic-loading-of-external-JavaScript-.js-files.html"69written that window.eval(str) will be eval string in global namespace, but for IE this is incorrect,70and you must register all functions in global namespace manually71*/7273eval(str);7475var matchAll = new RegExp(js_FunctionNameFragment, 'img');76var matchOne = new RegExp(js_FunctionNameFragment, 'im');7778var arr = str.match(matchAll) || [];7980for (var i = 0; i < arr.length; i++)81{82var fname = (arr[i].match(matchOne))[1];83if (eval('typeof(' + fname + ')') == 'function') window[fname] = eval(fname);84}85}8687/*88Load script and wait until it loads.89(if appent script element to DOM, Firefox does not wait until loading was completed)90*/91function js_loadScript(src)92{93var ex;94var req = null;9596if (window.XMLHttpRequest)97{98req = new XMLHttpRequest();99}100else101if (window.ActiveXObject)102{103var msxmls = ['Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];104for (var i = 0; i < msxmls.length; i++)105{106try107{108req = new ActiveXObject(msxmls[i]);109break;110}111catch (ex) {}112}113}114115if (req===null || req===false)116{117alert('Unable find XMLHttpRequest or it ActiveX alalog.');118return;119}120121req.open("GET", src, false);// not asynchronous122req.send(null);123124if (req.status == 200) js_EvalString(req.responseText);125else alert('Unable to load ' + src + ' (' + req.status + ')');126}127128function js_evalScripts(str)129{130var ex;131var arr = js_extractScripts(str);132133for (var i = 0; i < arr.length; i++)134{135switch (arr[i][0])136{137case 'src':138js_loadScript(arr[i][1]);139break;140141case 'code':142var cnt = arr[i][1];143144// hack for RadTabStrip145// but the best way is set HttpContext.Current.Request["httprequest"] to true in code behind146cnt = cnt.replace(/AppendStyleSheet\(false,/g, 'AppendStyleSheet(true,');147148js_EvalString(cnt);149break;150}151}152}153154function js_updateElement(element)155{156var content = element.innerHTML;157setTimeout(function() {js_evalScripts(content)}, 1);158}159160var js_postbackElement;161162function js_beginRequestHandler(sender, args)163{164js_postbackElement = args.get_postBackElement();165166//var updatedPanels = args.get_panelsUpdated();167//alert(updatedPanels.length);168}169170function js_pageLoadedHandler(sender, args)171{172if (typeof(js_postbackElement) === "undefined") return;173174var updatedPanels = args.get_panelsUpdated();175for (var i = 0; i < updatedPanels.length; i++) js_updateElement(updatedPanels[i]);176}177178function js_registerJsEval()179{180var ex;181182// don't display error if EnablePartialRendering is false183try184{185Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(js_beginRequestHandler);186Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(js_pageLoadedHandler);187}188catch (ex) {}189}190</script>
No comments:
Post a Comment