473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1669
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: usl2222 | last post by:
Hi folks, I appreciate any assistance in the following problem: I have a form with a bunch of dynamic controls on it. All the controls are dynamically generated on a server, including all...
2
by: Miguel | last post by:
Hi, I'm developing an application in C# with Windows Forms for my company that is similar to the MSN Messenger. This application uses a webservice for registering users, etc... and as 2...
8
by: David Thielen | last post by:
Hi; In our setup program how do I determine if I need to run "aspnet_regiis –i" and if so, is there an API I can calll rather than finding that program on the user's disk and calling it? --...
0
by: Global Infotech Corporation | last post by:
Hi We have the following two positions open at one of our Client's site in the Silicon Valley, CA area. Our client, apart from being a pioneer in desktop publishing software provider, also makes...
1
by: shivkumar2004 | last post by:
Hi!, I am developing a chat system using vb.net in vs 2005. I am getting the following error while registering the events. error details: System.InvalidOperationException was unhandled...
0
by: shivkumar2004 | last post by:
Hi, I m getting the following error while registering the events on client appl. error: "An error occurred creating the form. See Exception.InnerException for details. The error is: Exception...
0
by: applejump | last post by:
Hi all, I'm a Python beginner and trying to run the codes from Chapter 5 of Python pramming on win32. But when I tested the COM object with VBA, I got an error msg saying runtime error 438. Is...
0
by: davidj411 | last post by:
when does is make sense to use a ASP style Page (.psp) over a Python- based CGI script with IIS. ? http://support.microsoft.com/kb/276494 ASP requires registering the python engine. which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.