473,383 Members | 1,792 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,383 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 29697
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.