Re: Need Help with Registering Client Scripts



On Jun 7, 11:55 am, "Jonathan Wood" <jw...@xxxxxxxxxxxxxxxx> wrote:
use this method to check wheiter script already added or not...

Page.ClientScript.IsClientScriptBlockRegistered();

and to register use

Page.ClientScript.RegisterClientScriptBlock();

Well, thanks. But not only does this not address the problem I've described,
you're telling me to do exactly what the code I posted shows I was already
doing.

--
Jonathan Wood
SoftCircuits Programminghttp://www.softcircuits.com

"Munna" <munna...@xxxxxxxxx> wrote in message

news:085ec46d-cee3-4b9b-9e8a-1c8fc7d3368b@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jun 7, 11:08 am, "Jonathan Wood" <jw...@xxxxxxxxxxxxxxxx> wrote:

I'm trying to duplicate an HTML sample I have using my ASP.NET pages.

The sample contains the following within the <head> tag:

<script type="text/javascript" src="flashobject.js"></script>
<script type="text/javascript">
// <![CDATA[
var args = new Object();
var query = location.search.substring(1);
// Get query string
var pairs = query.split( "," );
// Break at comma
for ( var i = 0; i < pairs.length; i++ )
{
var pos = pairs[i].indexOf('=');
if( pos == -1 )
{
continue; // Look for "name=value"
}
var argname = pairs[i].substring( 0, pos ); // If not found, skip
var value = pairs[i].substring( pos + 1 ); // Extract the name
args[argname] = unescape( value ); // Extract the value
}
// ]]>
</script>

To do this the ASP.NET way, I added the following code to my Page_Load
handler:

if (!Page.ClientScript.IsClientScriptBlockRegistered("FlashObject"))
Page.ClientScript.RegisterClientScriptInclude(typeof(Page),
"FlashObject", "flashobject.js");

if (!Page.ClientScript.IsStartupScriptRegistered("PrepVideo"))
Page.ClientScript.RegisterStartupScript(typeof(Page), "PrepVideo",
"var args=new Object();" +
"var query=location.search.substring(1);" +
"var pairs=query.split(',');" +
"for (var i=0;i < pairs.length;i++){" +
"var pos=pairs[i].indexOf('=');" +
"if (pos==-1) continue;" +
"var argname=pairs[i].substring(0,pos);" +
"var value=pairs[i].substring(pos + 1);" +
"args[argname]=unescape(value);}", true);
}

I assume the second script is a start-up script since it is not a callable
function. So this seems like it should work but it does not duplicate the
functionality of the sample.

Looking at the HTML produced, I see neither registered scripts are placed
within the <head> tag. So instead of calling RegisterClientScriptInclude
and
RegisterStartupScript, I instead forced these scripts into the <head> tag
and they WORKED!!

Unfortunately, I need to put this in a control that really should register
the scripts in an organized way.

Is there any way to register a script such that it is inserted within the
<head> tag? Or perhaps there's something else I'm missing?

Thanks.

Jonathan

Hi Jonathan

"RegisterStartupScript" add scripts just before the end of "</body>"
tag..
and "RegisterClientScriptBlock" add script inside the form as far as i
seen so far..
well since you need the script in the head block here is a work around
i found and worked for me...

i added a literal control in size the head tag

<head id="Myhead" runat="server">
<title>Untitled Page</title>
<asp:Literal ID="ScriptSource" runat="server"></asp:Literal>
</head>

and in page load event i did this

ScriptSource.Text = "<script>window.alert('Worked okay');</script>";

surely you need to do some coding to adjust what you want to insert in
head...

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
.



Relevant Pages

  • RegisterClientScriptInclude and master page
    ... script tags inside of the <head> tag? ... I'm using RegisterClientScriptInclude inside of Page_Load event in the ... however it puts them inside where the tag begins on the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: More than a single script block within a single HEAD and BODY
    ... Can there be more than a single script block in a given HEAD tag? ... The W3C HTML validator lets you paste markup directly into the validation form. ...
    (comp.lang.javascript)
  • Re: *Solved* Why doesnt this page display anything in IE6?
    ... short tag for, and instead requires that the end tag be ... is for these platforms and if this is your only audience then code for those ... renders but scripts broken in Opera ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re:
    ... always had that in .NET and the server never had any trouble adding tags ... In framework 1 it didn't add anything to the head. ... need to be able to access the head tag as a server object? ... it would have to locate the LiteralControl ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Why people use this style of javascript declaration?
    ... The reason is historical. ... Netscape 2.x, and it did not support external .js files, only scripts ... Respectively tag was added to HTML specs as the one requiring ... the external .js file executed and inline content ignored. ...
    (comp.lang.javascript)