473,788 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ 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 2420
Why you try to make it harder...
There is more simple solutions
1- add html <Basetag after head..
2- make <head runat="server"t hen u can access it from code and add
anything you want here is example

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

Literal baseurl = new Literal();
baseurl.Text = string.Format(" <base href=\"{0}\">",
ConfigurationMa nager.AppSettin gs.Get("BaseURL "));
HtmlMeta desc = new HtmlMeta();
desc.Name = "Descriptio n";
desc.Content = Convert.ToStrin g(hdt.Rows[0]["Descriptio n"]);

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

Literal additional = new Literal();
additional.Text =
Convert.ToStrin g(hdt.Rows[0]["AdditinalHeadT ags"]);

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

"Boris Yeltsin" <bo****@nospam. nospamwrote in message
news:B0******** *************** ***********@mic rosoft.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"t hen u can access it from code and add
anything you want here is example

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

Literal baseurl = new Literal();
baseurl.Text = string.Format(" <base href=\"{0}\">",
ConfigurationMa nager.AppSettin gs.Get("BaseURL "));
HtmlMeta desc = new HtmlMeta();
desc.Name = "Descriptio n";
desc.Content = Convert.ToStrin g(hdt.Rows[0]["Descriptio n"]);

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

Literal additional = new Literal();
additional.Text =
Convert.ToStrin g(hdt.Rows[0]["AdditinalHeadT ags"]);

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

"Boris Yeltsin" <bo****@nospam. nospamwrote in message
news:B0******** *************** ***********@mic rosoft.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******** *************** ***********@mic rosoft.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"t hen u can access it from code and add
anything you want here is example

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

Literal baseurl = new Literal();
baseurl.Text = string.Format(" <base href=\"{0}\">",
ConfigurationM anager.AppSetti ngs.Get("BaseUR L"));
HtmlMeta desc = new HtmlMeta();
desc.Name = "Descriptio n";
desc.Content =
Convert.ToStri ng(hdt.Rows[0]["Descriptio n"]);

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

Literal additional = new Literal();
additional.Text =
Convert.ToStri ng(hdt.Rows[0]["AdditinalHeadT ags"]);

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

"Boris Yeltsin" <bo****@nospam. nospamwrote in message
news:B0******* *************** ************@mi crosoft.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******** *************** ***********@mic rosoft.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"t hen u can access it from code and add
anything you want here is example

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

Literal baseurl = new Literal();
baseurl.Text = string.Format(" <base href=\"{0}\">",
ConfigurationMa nager.AppSettin gs.Get("BaseURL "));
HtmlMeta desc = new HtmlMeta();
desc.Name = "Descriptio n";
desc.Content =
Convert.ToStrin g(hdt.Rows[0]["Descriptio n"]);

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

Literal additional = new Literal();
additional.Text =
Convert.ToStrin g(hdt.Rows[0]["AdditinalHeadT ags"]);

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

"Boris Yeltsin" <bo****@nospam. nospamwrote in message
news:B0******** *************** ***********@mic rosoft.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=serv er" 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="javas cript" src='<%= ResolveUrl("~/scripts/myscript.js")
%>'></script>
.............
</head>
<body>
===============

the "~/scripts/" path will be resolved by the "Page.ResolveUr l" 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=serv er" 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="javas cript" src='<%= ResolveUrl("~/scripts/myscript.js")
%>'></script>
.............
</head>
<body>
===============

the "~/scripts/" path will be resolved by the "Page.ResolveUr l" 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.Con trols.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.M asterPage
{
protected void Page_Load(objec t sender, EventArgs e)
{
Page.Header.Dat aBind();

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

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 <headersectio n, you can add
them into <formelement, just as those <scriptblocks registered through
Page.ClientScri pt.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
1395
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
2340
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
263
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
1964
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: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate.
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
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 we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.