472,378 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 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 1598
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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.