469,307 Members | 2,206 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,307 developers. It's quick & easy.

Need Help with Registering Client Scripts

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

The sample contains the following within the <headtag:

<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(type of(Page),
"FlashObject", "flashobject.js");

if (!Page.ClientScript.IsStartupScriptRegistered("Pre pVideo"))
Page.ClientScript.RegisterStartupScript(typeof(Pag e), "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 <headtag. So instead of calling RegisterClientScriptInclude and
RegisterStartupScript, I instead forced these scripts into the <headtag
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
<headtag? Or perhaps there's something else I'm missing?

Thanks.

Jonathan

Jun 27 '08 #1
4 1527
On Jun 7, 11:08*am, "Jonathan Wood" <jw...@softcircuits.comwrote:
I'm trying to duplicate an HTML sample I have using my ASP.NET pages.

The sample contains the following within the <headtag:

* *<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 notfound, skip
* * * * *var value = pairs[i].substring( pos + 1 ); // Extractthe 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(typ eof(Page),
"FlashObject", "flashobject.js");

* if (!Page.ClientScript.IsStartupScriptRegistered("Pre pVideo"))
* *Page.ClientScript.RegisterStartupScript(typeof(Pa ge), "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 <headtag. So instead of calling RegisterClientScriptInclude and
RegisterStartupScript, I instead forced these scripts into the <headtag
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
<headtag? Or perhaps there's something else I'm missing?

Thanks.

Jonathan
Hi

use this method to check wheiter script already added or not...

Page.ClientScript.IsClientScriptBlockRegistered();

and to register use

Page.ClientScript.RegisterClientScriptBlock();

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
Jun 27 '08 #2
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 Programming
http://www.softcircuits.com

"Munna" <mu******@gmail.comwrote in message
news:08**********************************@j1g2000p rb.googlegroups.com...
On Jun 7, 11:08 am, "Jonathan Wood" <jw...@softcircuits.comwrote:
I'm trying to duplicate an HTML sample I have using my ASP.NET pages.

The sample contains the following within the <headtag:

<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(type of(Page),
"FlashObject", "flashobject.js");

if (!Page.ClientScript.IsStartupScriptRegistered("Pre pVideo"))
Page.ClientScript.RegisterStartupScript(typeof(Pag e), "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 <headtag. So instead of calling RegisterClientScriptInclude
and
RegisterStartupScript, I instead forced these scripts into the <headtag
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
<headtag? Or perhaps there's something else I'm missing?

Thanks.

Jonathan

Jun 27 '08 #3
On Jun 7, 11:55 am, "Jonathan Wood" <jw...@softcircuits.comwrote:
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...@gmail.comwrote in message

news:08**********************************@j1g2000p rb.googlegroups.com...
On Jun 7, 11:08 am, "Jonathan Wood" <jw...@softcircuits.comwrote:
I'm trying to duplicate an HTML sample I have using my ASP.NET pages.
The sample contains the following within the <headtag:
<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(type of(Page),
"FlashObject", "flashobject.js");
if (!Page.ClientScript.IsStartupScriptRegistered("Pre pVideo"))
Page.ClientScript.RegisterStartupScript(typeof(Pag e), "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 <headtag. So instead of calling RegisterClientScriptInclude
and
RegisterStartupScript, I instead forced these scripts into the <headtag
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
<headtag? 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
Jun 27 '08 #4
I figured this out. Turns out that it is not necessary for these scripts to
be within the <headtag. I don't understand exactly how they are used but
if I don't register the second script as a startup script and instead
register it as a regular client script block, it appears to work just fine.
Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Munna" <mu******@gmail.comwrote in message
news:d5**********************************@z24g2000 prf.googlegroups.com...
On Jun 7, 11:55 am, "Jonathan Wood" <jw...@softcircuits.comwrote:
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...@gmail.comwrote in message

news:08**********************************@j1g2000 prb.googlegroups.com...
On Jun 7, 11:08 am, "Jonathan Wood" <jw...@softcircuits.comwrote:
I'm trying to duplicate an HTML sample I have using my ASP.NET pages.
The sample contains the following within the <headtag:
<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(type of(Page),
"FlashObject", "flashobject.js");
if (!Page.ClientScript.IsStartupScriptRegistered("Pre pVideo"))
Page.ClientScript.RegisterStartupScript(typeof(Pag e), "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 <headtag. 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
<headtag? 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
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by David Thielen | last post: by
1 post views Thread by shivkumar2004 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.