Re: Need Help with Registering Client Scripts
- From: Munna <munnaonc@xxxxxxxxx>
- Date: Sat, 7 Jun 2008 00:43:55 -0700 (PDT)
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
.
- Follow-Ups:
- Re: Need Help with Registering Client Scripts
- From: Jonathan Wood
- Re: Need Help with Registering Client Scripts
- References:
- Need Help with Registering Client Scripts
- From: Jonathan Wood
- Re: Need Help with Registering Client Scripts
- From: Munna
- Re: Need Help with Registering Client Scripts
- From: Jonathan Wood
- Need Help with Registering Client Scripts
- Prev by Date: Re: Fileupload an MDB?
- Next by Date: Re: web service for reverse lookup phone number
- Previous by thread: Re: Need Help with Registering Client Scripts
- Next by thread: Re: Need Help with Registering Client Scripts
- Index(es):
Relevant Pages
|