I really hate the way Extender controls, Asp.net script controls that emit javascript all at the top of the web page and just was rethinking of any other way to emit it at the bottom similar to what,
ClientScriptMana开发者_开发技巧ger.RegisterStartupScript
. On looking into this post by DanWahlin i think it is possible but i would have to handle all dirty work of seeing of script is included twice and making sure all necessary scripts are included in order. So my question boils down to this
"I am developing custom controls, Extender controls and i want all my scripts emitted to be at bottom of webpage, What options do you suggest and Why"
Note: These scripts and also css are embedded as web resources
As long as we are talking about MS AJAX Toolkit there is an option in the Toolkit ScriptManager that is called "LoadScriptsBeforeUI". Setting this to "false" would allow you to get your UI loaded before the scripts, if this is your goal.
I am generally wondering why having scripts in the top of a webpage would bother you, for it is a general practice and you see any impact only if your connection is extremely slow.
AFAIK you have to handle the OnRender part of the page. I was doing something similar but to move the viewstate of the page for SEO thing
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
base.Render(htmlWriter);
string html = stringWriter.ToString();
int startPoint = -1;
int endPoint = -1;
startPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");
if (startPoint >= 0)
{
endPoint = html.IndexOf("/>", startPoint) + 2;
string viewstateInput = html.Substring(startPoint, endPoint - startPoint);
html = html.Remove(startPoint, endPoint - startPoint);
int FormEndStart = html.IndexOf("</form>") - 1;
if (FormEndStart >= 0)
html = html.Insert(FormEndStart + 1, viewstateInput);
}
}
Maybe you can do the same lokking for script tag. Other way I can thing of is to put a <%=MyVar%> at the end of the page, so you can set it from the code behind, but I guess is too much couplig with the page
Actually speaking you can't with the current implementation of the ajax extender controls. So i managed to rely on client script dependency framework like script.js
instead. I did achieve that i wanted.
精彩评论