473,394 Members | 1,774 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,394 software developers and data experts.

How to implement ClientScript.RegisterClientScriptInclude

Hi guys,

I'm using asp.net 2.0, can anybody send me some complete examples on using
ClientScript.RegisterClientScriptInclude and
ClientScript.RegisterClientScriptSource, for registering an external
javascript file (myfile.js) in my ASP page, I have not found any clear or
complete examples, meaning in wich event handler should I put it in
page_load? if I'm using a master page where is the correct place to put it
in?
please any help would be very appreciated.

Regards

Feb 22 '07 #1
2 29699
Howdy,

1. declaratively (aspx page code)
<script language="javascript" src="<%=ResolveClientUrl("~/scripts/timer.js")
%"></script>

or programmatically in master page load / init/ prerender / any event
handlers:
Page.ClientScript.RegisterClientScriptInclude("my" ,
ResolveClientUrl("~/scripts/timer.js"));

2. i reckon instead of ClientScript.RegisterClientScriptSource you meant
ClientScript.RegisterClientScriptBlock (or if i got you wrong, do you use
store javascripts in a resource file?)
If i got you right, try this:

protected void Page_Load(object sender, EventArgs e)
{
RegisterMessageScript("Hello World!");
}

private void RegisterMessageScript(string message)
{
System.Text.StringBuilder script =
new System.Text.StringBuilder();

script.Append("<script language=\"javascript\">\n");
script.AppendFormat("alert('{0}');\n", message);
script.Append("</script>\n");

Type type = this.GetType();

if(!ClientScript.IsClientScriptBlockRegistered(typ e, "messageScript"))
ClientScript.RegisterClientScriptBlock(type, "messageScript",
script.ToString());

}

hope this helps

Milosz
"verci" wrote:
Hi guys,

I'm using asp.net 2.0, can anybody send me some complete examples on using
ClientScript.RegisterClientScriptInclude and
ClientScript.RegisterClientScriptSource, for registering an external
javascript file (myfile.js) in my ASP page, I have not found any clear or
complete examples, meaning in wich event handler should I put it in
page_load? if I'm using a master page where is the correct place to put it
in?
please any help would be very appreciated.

Regards

Feb 22 '07 #2
Hi Milosz,

First, thank you so much for your complete answer. :)

Second, sorry about that bunch of posts but my outlook express was acting
weird, kept closing when I tried to post messages.
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:E4**********************************@microsof t.com...
Howdy,

1. declaratively (aspx page code)
<script language="javascript"
src="<%=ResolveClientUrl("~/scripts/timer.js")
%"></script>

or programmatically in master page load / init/ prerender / any event
handlers:
Page.ClientScript.RegisterClientScriptInclude("my" ,
ResolveClientUrl("~/scripts/timer.js"));

2. i reckon instead of ClientScript.RegisterClientScriptSource you meant
ClientScript.RegisterClientScriptBlock (or if i got you wrong, do you use
store javascripts in a resource file?)
If i got you right, try this:

protected void Page_Load(object sender, EventArgs e)
{
RegisterMessageScript("Hello World!");
}

private void RegisterMessageScript(string message)
{
System.Text.StringBuilder script =
new System.Text.StringBuilder();

script.Append("<script language=\"javascript\">\n");
script.AppendFormat("alert('{0}');\n", message);
script.Append("</script>\n");

Type type = this.GetType();

if(!ClientScript.IsClientScriptBlockRegistered(typ e, "messageScript"))
ClientScript.RegisterClientScriptBlock(type, "messageScript",
script.ToString());

}

hope this helps

Milosz
"verci" wrote:
>Hi guys,

I'm using asp.net 2.0, can anybody send me some complete examples on
using
ClientScript.RegisterClientScriptInclude and
ClientScript.RegisterClientScriptSource, for registering an external
javascript file (myfile.js) in my ASP page, I have not found any clear or
complete examples, meaning in wich event handler should I put it in
page_load? if I'm using a master page where is the correct place to put
it
in?
please any help would be very appreciated.

Regards


Feb 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: sck10 | last post by:
Hello, I have the following sub in a class in my "App_Code" directory. The script is for setting focus on a particular control, but I get the error, "Name ClientScript Not declared". Also, I am...
1
by: Tom | last post by:
I am new to ASP.NET. I am converting a fairly good sized app from classic to .net. Some of my pages have a lot of controls and javascript functions. I would like to keep these intact as much as...
0
by: Dunc | last post by:
Hi, I've got an ASP.NET 2.0 app, and I'm trying to incorporate Google Maps. The app uses nested master pages, so it seems the only way to add a <scripttag to the header block is to use...
0
by: verci | last post by:
Hi guys, Can anybody sent me some good examples on using ClientScript.RegisterClientScriptInclude and ClientScript.RegisterClientScriptSource, I've just haven't found much info on how to use...
2
by: verci | last post by:
Hi guys, I'm using asp.net 2.0, can anybody send me some complete examples on using ClientScript.RegisterClientScriptInclude and ClientScript.RegisterClientScriptSource, for registering an...
1
by: HockeyFan | last post by:
My function to get an alert box on the page isn't working. Instead it puts in the bottom section of the page: <script type="text/javascript"> <!-- This is a test// --> </script> The...
9
by: Dariusz Tomoń | last post by:
Hello, I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not directly from i.e. default.aspx.cs code but from a class belonging to DLL, which is referred in my project. The code...
6
by: Danielle | last post by:
Greetings all - I am working on a vb .NET asp web application. I have a button that opens a new page when clicked. It works fine; the problem is when the user refreshes the original page, the...
1
by: Dave Mathew | last post by:
Is there any way to use RegisterClientScriptInclude to generate the script tags inside of the <headtag? I'm using RegisterClientScriptInclude inside of Page_Load event in the code behind for the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.