473,473 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

It's trying to compile my JavaScript?

I use Master Pages, so I make use of URL rebasing through the ~ operator,
like this in the <head>:
<link runat="server" href="~/Root.master.css" media="screen"
rel="stylesheet" type="text/css" />

It works perfectly and the ~ gets converted by the server into the correct
relative path. Great!

Now, I put this in the <head>:
<script type="text/javascript" src="~/Root.master.js"
runat="server"></script>

And everything screws up. It looks like it's trying to compile that .js file
into the page as the CLR throws up syntax errors and compiler errors in my
JavaScript (which is valid JavaScript).

What am I doing wrong? :(
Aug 23 '06 #1
9 2399
Why you try to make it harder...
There is more simple solutions
1- add html <Basetag after head..
2- make <head runat="server"then u can access it from code and add
anything you want here is example

foreach (Control ctrl in this.Master.Controls)
{
if (ctrl is HtmlHead)
{
HtmlTitle title = new HtmlTitle();
title.Text = Convert.ToString(hdt.Rows[0]["Title"]);

Literal baseurl = new Literal();
baseurl.Text = string.Format("<base href=\"{0}\">",
ConfigurationManager.AppSettings.Get("BaseURL"));
HtmlMeta desc = new HtmlMeta();
desc.Name = "Description";
desc.Content = Convert.ToString(hdt.Rows[0]["Description"]);

HtmlMeta keyword = new HtmlMeta();
keyword.Name = "Keyword";
keyword.Content = Convert.ToString(hdt.Rows[0]["Keyword"]);

Literal additional = new Literal();
additional.Text =
Convert.ToString(hdt.Rows[0]["AdditinalHeadTags"]);

HtmlHead head = (HtmlHead)ctrl;
head.Controls.AddAt(0, title);
head.Controls.AddAt(1, baseurl);
head.Controls.AddAt(2, desc);
head.Controls.AddAt(3, keyword);
head.Controls.AddAt(4, additional);
}

"Boris Yeltsin" <bo****@nospam.nospamwrote in message
news:B0**********************************@microsof t.com...
>I use Master Pages, so I make use of URL rebasing through the ~ operator,
like this in the <head>:
<link runat="server" href="~/Root.master.css" media="screen"
rel="stylesheet" type="text/css" />

It works perfectly and the ~ gets converted by the server into the correct
relative path. Great!

Now, I put this in the <head>:
<script type="text/javascript" src="~/Root.master.js"
runat="server"></script>

And everything screws up. It looks like it's trying to compile that .js
file
into the page as the CLR throws up syntax errors and compiler errors in my
JavaScript (which is valid JavaScript).

What am I doing wrong? :(

Aug 23 '06 #2
Hi Islamegy,

1) I'm not sure this will work for me. Doesn't the <basetag need an
absolute URL? Even if it takes a relative URL, I'll still have to do
something to update the 'href' attribute on the fly to make it point to the
right level, such as:
<base href="~/" runat="server" />
(which doesn't work - I tried it - but ASP.NET doesn't parse the ~)

2) I'm using code-behind solutions for adding dynamic meta-tags, but that's
because they're dynamic. My JavaScript file is fixed, so I'd much prefer the
reference in the markup and not in the code-behind :)

Thanks...

"Islamegy®" wrote:
Why you try to make it harder...
There is more simple solutions
1- add html <Basetag after head..
2- make <head runat="server"then u can access it from code and add
anything you want here is example

foreach (Control ctrl in this.Master.Controls)
{
if (ctrl is HtmlHead)
{
HtmlTitle title = new HtmlTitle();
title.Text = Convert.ToString(hdt.Rows[0]["Title"]);

Literal baseurl = new Literal();
baseurl.Text = string.Format("<base href=\"{0}\">",
ConfigurationManager.AppSettings.Get("BaseURL"));
HtmlMeta desc = new HtmlMeta();
desc.Name = "Description";
desc.Content = Convert.ToString(hdt.Rows[0]["Description"]);

HtmlMeta keyword = new HtmlMeta();
keyword.Name = "Keyword";
keyword.Content = Convert.ToString(hdt.Rows[0]["Keyword"]);

Literal additional = new Literal();
additional.Text =
Convert.ToString(hdt.Rows[0]["AdditinalHeadTags"]);

HtmlHead head = (HtmlHead)ctrl;
head.Controls.AddAt(0, title);
head.Controls.AddAt(1, baseurl);
head.Controls.AddAt(2, desc);
head.Controls.AddAt(3, keyword);
head.Controls.AddAt(4, additional);
}

"Boris Yeltsin" <bo****@nospam.nospamwrote in message
news:B0**********************************@microsof t.com...
I use Master Pages, so I make use of URL rebasing through the ~ operator,
like this in the <head>:
<link runat="server" href="~/Root.master.css" media="screen"
rel="stylesheet" type="text/css" />

It works perfectly and the ~ gets converted by the server into the correct
relative path. Great!

Now, I put this in the <head>:
<script type="text/javascript" src="~/Root.master.js"
runat="server"></script>

And everything screws up. It looks like it's trying to compile that .js
file
into the page as the CLR throws up syntax errors and compiler errors in my
JavaScript (which is valid JavaScript).

What am I doing wrong? :(


Aug 23 '06 #3
i don't know why u don't add it dynamicly like you do in meta tags, so u
don't have to change it the masterpage or forms, u can store it fixed in
web.config and add it from code behind.. easy huh?

you masy also right it like this
<script type="text/javascript" src="/scripts/master.js">
when use just "/" it's mean relative path from the root..

That's all i have..


"Boris Yeltsin" <bo****@nospam.nospamwrote in message
news:32**********************************@microsof t.com...
Hi Islamegy,

1) I'm not sure this will work for me. Doesn't the <basetag need an
absolute URL? Even if it takes a relative URL, I'll still have to do
something to update the 'href' attribute on the fly to make it point to
the
right level, such as:
<base href="~/" runat="server" />
(which doesn't work - I tried it - but ASP.NET doesn't parse the ~)

2) I'm using code-behind solutions for adding dynamic meta-tags, but
that's
because they're dynamic. My JavaScript file is fixed, so I'd much prefer
the
reference in the markup and not in the code-behind :)

Thanks...

"Islamegy®" wrote:
>Why you try to make it harder...
There is more simple solutions
1- add html <Basetag after head..
2- make <head runat="server"then u can access it from code and add
anything you want here is example

foreach (Control ctrl in this.Master.Controls)
{
if (ctrl is HtmlHead)
{
HtmlTitle title = new HtmlTitle();
title.Text = Convert.ToString(hdt.Rows[0]["Title"]);

Literal baseurl = new Literal();
baseurl.Text = string.Format("<base href=\"{0}\">",
ConfigurationManager.AppSettings.Get("BaseURL") );
HtmlMeta desc = new HtmlMeta();
desc.Name = "Description";
desc.Content =
Convert.ToString(hdt.Rows[0]["Description"]);

HtmlMeta keyword = new HtmlMeta();
keyword.Name = "Keyword";
keyword.Content =
Convert.ToString(hdt.Rows[0]["Keyword"]);

Literal additional = new Literal();
additional.Text =
Convert.ToString(hdt.Rows[0]["AdditinalHeadTags"]);

HtmlHead head = (HtmlHead)ctrl;
head.Controls.AddAt(0, title);
head.Controls.AddAt(1, baseurl);
head.Controls.AddAt(2, desc);
head.Controls.AddAt(3, keyword);
head.Controls.AddAt(4, additional);
}

"Boris Yeltsin" <bo****@nospam.nospamwrote in message
news:B0**********************************@microso ft.com...
>I use Master Pages, so I make use of URL rebasing through the ~
operator,
like this in the <head>:
<link runat="server" href="~/Root.master.css" media="screen"
rel="stylesheet" type="text/css" />

It works perfectly and the ~ gets converted by the server into the
correct
relative path. Great!

Now, I put this in the <head>:
<script type="text/javascript" src="~/Root.master.js"
runat="server"></script>

And everything screws up. It looks like it's trying to compile that .js
file
into the page as the CLR throws up syntax errors and compiler errors in
my
JavaScript (which is valid JavaScript).

What am I doing wrong? :(



Aug 23 '06 #4
Hi again,

I'm running from the ASP.NET web server, so the root of the application
isn't the root of the server, e.g.:
http://localhost:4629/MyApplication/Home.aspx

So I can't just a straight / without rebasing it with the ~ (or another
method)

Thanks again for trying!

"Islamegy®" wrote:
i don't know why u don't add it dynamicly like you do in meta tags, so u
don't have to change it the masterpage or forms, u can store it fixed in
web.config and add it from code behind.. easy huh?

you masy also right it like this
<script type="text/javascript" src="/scripts/master.js">
when use just "/" it's mean relative path from the root..

That's all i have..


"Boris Yeltsin" <bo****@nospam.nospamwrote in message
news:32**********************************@microsof t.com...
Hi Islamegy,

1) I'm not sure this will work for me. Doesn't the <basetag need an
absolute URL? Even if it takes a relative URL, I'll still have to do
something to update the 'href' attribute on the fly to make it point to
the
right level, such as:
<base href="~/" runat="server" />
(which doesn't work - I tried it - but ASP.NET doesn't parse the ~)

2) I'm using code-behind solutions for adding dynamic meta-tags, but
that's
because they're dynamic. My JavaScript file is fixed, so I'd much prefer
the
reference in the markup and not in the code-behind :)

Thanks...

"Islamegy®" wrote:
Why you try to make it harder...
There is more simple solutions
1- add html <Basetag after head..
2- make <head runat="server"then u can access it from code and add
anything you want here is example

foreach (Control ctrl in this.Master.Controls)
{
if (ctrl is HtmlHead)
{
HtmlTitle title = new HtmlTitle();
title.Text = Convert.ToString(hdt.Rows[0]["Title"]);

Literal baseurl = new Literal();
baseurl.Text = string.Format("<base href=\"{0}\">",
ConfigurationManager.AppSettings.Get("BaseURL"));
HtmlMeta desc = new HtmlMeta();
desc.Name = "Description";
desc.Content =
Convert.ToString(hdt.Rows[0]["Description"]);

HtmlMeta keyword = new HtmlMeta();
keyword.Name = "Keyword";
keyword.Content =
Convert.ToString(hdt.Rows[0]["Keyword"]);

Literal additional = new Literal();
additional.Text =
Convert.ToString(hdt.Rows[0]["AdditinalHeadTags"]);

HtmlHead head = (HtmlHead)ctrl;
head.Controls.AddAt(0, title);
head.Controls.AddAt(1, baseurl);
head.Controls.AddAt(2, desc);
head.Controls.AddAt(3, keyword);
head.Controls.AddAt(4, additional);
}

"Boris Yeltsin" <bo****@nospam.nospamwrote in message
news:B0**********************************@microsof t.com...
I use Master Pages, so I make use of URL rebasing through the ~
operator,
like this in the <head>:
<link runat="server" href="~/Root.master.css" media="screen"
rel="stylesheet" type="text/css" />

It works perfectly and the ~ gets converted by the server into the
correct
relative path. Great!

Now, I put this in the <head>:
<script type="text/javascript" src="~/Root.master.js"
runat="server"></script>

And everything screws up. It looks like it's trying to compile that .js
file
into the page as the CLR throws up syntax errors and compiler errors in
my
JavaScript (which is valid JavaScript).

What am I doing wrong? :(


Aug 23 '06 #5
Hi Boris,

since <script tag is a particular one, adding "runat=server" will not
work for it (<script runat="server" is used for server-side code block).
For your scenario, a simple way is to embed some server-side code
expression to output the absolute url(from application root directory). e.g.
===============
..............
<head runat="server">
..........

<script language="javascript" src='<%= ResolveUrl("~/scripts/myscript.js")
%>'></script>
.............
</head>
<body>
===============

the "~/scripts/" path will be resolved by the "Page.ResolveUrl" method and
always put the right path to the "script" subfolder under application's
root directory.

Hope this helps.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 24 '06 #6
Thanks Steven. I hoped there was another way, but that suits my needs for now.

Now, if the ASP.NET team could figure a way of being able to put script
inside attributes and keep the double-quotes on the attributes, that would be
great. It makes my View Source look ugly when one attribute on the page is
single-quoted and the rest are double ;)

I'll override the Render and change it back :p

Thanks again,
Boris

"Steven Cheng[MSFT]" wrote:
Hi Boris,

since <script tag is a particular one, adding "runat=server" will not
work for it (<script runat="server" is used for server-side code block).
For your scenario, a simple way is to embed some server-side code
expression to output the absolute url(from application root directory). e.g.
===============
..............
<head runat="server">
..........

<script language="javascript" src='<%= ResolveUrl("~/scripts/myscript.js")
%>'></script>
.............
</head>
<body>
===============

the "~/scripts/" path will be resolved by the "Page.ResolveUrl" method and
always put the right path to the "script" subfolder under application's
root directory.

Hope this helps.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 24 '06 #7
Hi Boris,

Yes, the single/double quote switch does be a headache when we mix
server-side code with html in the aspx template.

BTW, for the <scripttag here, I found that we can use nested double quot
without design-time or runtime error. e.g.

<script type="text/javascript" src="<%= ResolveUrl("~/scripts/myscript.js")
%>"></script>

I am using a C# page, is this also the case on your side? If so, at least
you can avoid mixing single/double quote for these <script tags here :-).

Thanks for your posting.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 24 '06 #8
OK Steven,

I think I'm going to cause you further headache.

Everything was going so well until I tried to modify the Header object on
the page and hit this:
"Error: The Controls collection cannot be modified because the control
contains code blocks (i.e. <% ... %>)"

from my call:
Page.Header.Controls.Add(.....)

Any other ideas for that style tag?
(I have 2 solutions in my head I don't want to use.. (1) some sort of
literal, (2) override the render and wedge the style tag in)

On the bright side, you were right about the double-quotes. They work in
this instance - I don't know why I've had problems with them in the past.
(I'm using VB.NET - the superior choice ;)

And you were right to change to type="text/javascript" - I think that
language attribute is depreciated now. (I'm using XHTML1.1)

- Boris

"Steven Cheng[MSFT]" wrote:
Hi Boris,

Yes, the single/double quote switch does be a headache when we mix
server-side code with html in the aspx template.

BTW, for the <scripttag here, I found that we can use nested double quot
without design-time or runtime error. e.g.

<script type="text/javascript" src="<%= ResolveUrl("~/scripts/myscript.js")
%>"></script>

I am using a C# page, is this also the case on your side? If so, at least
you can avoid mixing single/double quote for these <script tags here :-).

Thanks for your posting.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 24 '06 #9
Thanks for the followup Boris,

I'd admit that this is a headache and I haven't expected this error since I
never do the two things together before :(. Anyway, good to get it as
earlier as possible so that we will have to find a solution on it.

After some research, I'm afraid the general <%= %render exception can not
be used together with code which dynamically modify "Header" control's
Controls collection. currently we have the following options:
1. Use databinding expression (<%# %>) instead of <%= %render expression
to expose dynamic url in header's child controls. <%# %databinding
expression is constructed at runtime while <%= %is processed at compile
time. e.g.
===== in master page aspx=========
<head>
...........
<script type="text/javascript" src="<%#
ResolveUrl("~/scripts/myscript1.js") %>" ></script>
<script type="text/javascript" src="<%#
ResolveUrl("~/scripts/myscript2.js") %>" ></script>

</head>
================

=== in master page code behind==========
public partial class Master_site : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Page.Header.DataBind();

}
====================

We need to explicitly call "DataBind" method of Header to make the <%# %>
databinding expression get evaluated.

2. For script tags, instead of embed them in <headersection, you can add
them into <formelement, just as those <scriptblocks registered through
Page.ClientScript.XXXX methods. e.g.
===============
<form id="form1" runat="server">
<div id="divScripts" runat="server">
<script type="text/javascript" src="<%=
ResolveUrl("~/scripts/myscript3.js") %>" ></script>
<script type="text/javascript" src="<%=
ResolveUrl("~/scripts/myscript4.js") %>" ></script>
</div>
........................

===============

Hope this helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Aug 25 '06 #10

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

Similar topics

0
by: sgd | last post by:
trying to compile on my comp., but can't ,,, message tells me that i need to be running IIS under the .Net framework 1.1, not sure how to do this,,, any help is needed.
22
by: Canonical Latin | last post by:
#include<iostream> int main() { char buff; std::cin.getline(buff,3); std::cin.getline(buff,3); std::cout << buff << endl; } Run at command prompt and input 1234567 what do you get as output?
0
by: sgd | last post by:
trying to compile on my comp., but can't ,,, message tells me that i need to be running IIS under the .Net framework 1.1, not sure how to do this,,, any help is needed.
5
by: Michael | last post by:
Hi All, I have three very simple files as below. When I try and compile these with g++ -ansi -Wall -pedantic -o crap Base.h Other.h I get an error: Base.h:7: internal compiler error:...
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
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...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.