CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 7/23/2005 12:50:55 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 11 Views: 34 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
12 Items, 1 Pages 1 |< << Go >> >|
Shuf
Asp.Net User
Javascript and Master Page problem7/23/2005 12:50:55 PM

0/0

Hello

I have a master page which I put inside my MasterPages folder, which is under the root directory. And then, I've created a few other pages which uses this master page. In the master page, I've put a link to a script file, for example myscript.js, which is under Script folder. Here's the hirearchy

Root -
- MasterPages
- Scripts
- About
- Help

My problem is when i tried to view pages which is the same level as the MasterPages, for example pages directly in About and Help folders, the javascript loads up fine, but when i tried to view pages which are directly under the Root, the script doesnt load. I've tried both .. and ~ in the url. what could went wrong?

BrockAllen
Asp.Net User
Re: Javascript and Master Page problem7/23/2005 3:43:57 PM

0/0

Yes, external file references from the matser are relative to the page that's being executed, not the master. So, in the master make your control runat=server and use the ~/path to reference the external file. The ~ syntax doesn't work unless the tag/control is a server side control.

-Brock

DevelopMentor
http://staff.develop.com/ballen
Shuf
Asp.Net User
Re: Javascript and Master Page problem7/23/2005 7:01:37 PM

0/0

yes, i know about that already because i'm using ~ for images, and they load fine. Here's the code snippet from my work. If i'm using .., pages which are in the same level as master pages loads fine. but if i change it to ~, it doesnt load at all. it doesnt make much sense, because for css file, i just use .., and the pages are ok regardless of the hierarchy level. but for javascript, it's not the case. it will report an error; Object expected.

<head runat="server">
    <title>Example Site</title>
    <link href="../Styles/Style.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/NiftyCorners.css" rel="stylesheet" type="text/css" />

    <script src="../Scripts/Nifty.js" type="text/javascript"></script>

    <script type="text/javascript">
        window.onload=function(){
        if(!NiftyCheck())
            return;
        Rounded("div#doc_brc","all","transparent","#ffffff","border #cccccc");
        Rounded("div#searchBox_brc","all","#ffffff","#ffffff","border #cccccc");
        Rounded("div.header_brc","all","#ffffff","#f0f0f0","smooth");
        }
    </script>

</head>

here's some of the variation i've tried, and obviously not working.

<link href="../Scripts/Nifty.js" type="text/javascript"/>
<link href="../Scripts/Nifty.js" type="text/javascript" runat="server"/>
<link href="~/Scripts/Nifty.js" type="text/javascript"/>
<link href="~/Scripts/Nifty.js" type="text/javascript"/ runat="server">
<script src="../Scripts/Nifty.js" type="text/javascript"></script>
<script src="~/Scripts/Nifty.js" type="text/javascript" runat="server"></script>

if you need more than just the code i pasted above, please tell me and i'll email it to you

BrockAllen
Asp.Net User
Re: Javascript and Master Page problem7/23/2005 9:14:44 PM

0/0

<link rel=stylesheet type=text/css runat=server src="~/path/file.css" />

will work fine for CSS files.

For .js files you'll need to instead call:

Page.ClientScript.RegisterClientScriptInclude("MyKey", "~/path/file.js");

And you can do this from your master in the Page_Load event.

-Brock

DevelopMentor
http://staff.develop.com/ballen
Shuf
Asp.Net User
Re: Javascript and Master Page problem7/24/2005 1:14:50 PM

0/0

ok, I have included that code into my master page's Page_Load event, but it doesnt fix it. it will print

<script src="~/Scripts/Nifty.js" type="text/javascript"></script>

in the HTML code

I do not want to use absolute path if possible since if I want, I wont be asking this. Any idea?

BrockAllen
Asp.Net User
Re: Javascript and Master Page problem7/24/2005 3:59:32 PM

0/0

Gah, sorry I'm being so sloppy. Take the "~/path/file.js" and wrap it with a call to ResolveClientUrl.

-Brock

DevelopMentor
http://staff.develop.com/ballen
Shuf
Asp.Net User
Re: Javascript and Master Page problem7/24/2005 8:17:22 PM

0/0

awesome. it does work :D thanks a lot Brock.

One question tho, how can I put this into the head tag? This way I think I could make custom head content. But if it's a css file, would there be a designer support for it?

BrockAllen
Asp.Net User
Re: Javascript and Master Page problem7/24/2005 8:57:47 PM

0/0

HtmlGenericControl script = new HtmlGenericControl("script");
script.Attributes.Add(
"src", this.ResolveClientUrl("~/path/file.js"));
script.Attributes.Add(
"type", "text/javascript");
Page.Header.AddParsedSubObject(script);

-Brock


DevelopMentor
http://staff.develop.com/ballen
Shuf
Asp.Net User
Re: Javascript and Master Page problem7/25/2005 9:13:32 AM

0/0

That does the work. Thanks

What book would you suggest for me to read if I want to learn more about these API. I would like to grasp the basics of web development with aspx and to learn about some of the useful APIs.

I have become a life time member at LearnVisualStudio.net, which is awesome but a lot of the content there put more focus on v1.1. Do you know any good video tutorial for v2 as well?

Thanks

BrockAllen
Asp.Net User
Re: Javascript and Master Page problem7/25/2005 2:19:08 PM

0/0

The best thing I know of right now is the 2.0 QuickStarts:

http://beta.asp.net/quickstart/aspnet/Default.aspx

-Brock

DevelopMentor
http://staff.develop.com/ballen
Shuf
Asp.Net User
Re: Javascript and Master Page problem7/25/2005 9:39:23 PM

0/0

thanks again for the guide and help :D
WorkingMan2005
Asp.Net User
Re: Javascript and Master Page problem1/9/2006 7:56:50 PM

0/0

I hope I came across this post last week.

Here is what I used for a content page to use Javascript and that is also linked to a MasterPage.

// Define the name, type and url of the client script on the page.

String csname = "UtilScript";

String csurl = this.ResolveClientUrl("~/script/util.js"); //thanks to this post I update this with ResolveClientUrl

Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.

ClientScriptManager cs = Page.ClientScript;

// Check to see if the include script exists already.

if (!cs.IsClientScriptIncludeRegistered(cstype, csname))

{

cs.RegisterClientScriptInclude(cstype, csname, csurl);

}

The source code generated at runtime give you something like that (path will differ for different environment)

<script src="../script/util.js" type="text/javascript"></script>

Including the above line in your content file directly will not work (as I tried it) for whatever reason (maybe someone can provide a reason/solution). Including a .js is the easiest and safest way to include javascript content. This is the guaranteed way to successfully access javascript (otherwise you might get : object expected error) on the content page.

12 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Beginning ASP.NET 3.5: In C# and VB Authors: Imar Spaanjaars, Pages: 734, Published: 2008
ASP.NET 2.0 MVP Hacks and Tips Authors: David Yack, Joe Mayo, Scott Hanselman, Fredrik Normén, Dan Wahlin, J. Ambrose Little, Jonathan Goodyear, Pages: 400, Published: 2006
Professional ASP.NET 2.0 Authors: Bill Evjen, Scott Hanselman, Farhan Muhammad, Srinivasa Sivakumar, Devin Rader, Pages: 1253, Published: 2005
Microsoft Office SharePoint Server 2007: The Complete Reference Authors: David Matthew Sterling, David Sterling, Pages: 788, Published: 2007
Professional ASP.NET 3.5: In C# and VB Authors: Bill Evjen, Scott Hanselman, Devin Rader, Pages: 1673, Published: 2008
Amazon.com Mashups Authors: Francis Shanahan, Pages: 379, Published: 2006
Brilliant Microsoft Expression Web Authors: Steve Johnson, Pages: 366, Published: 2007
Pro ASP.NET 2.0 Website Programming Authors: Damon Armstrong, Pages: 641, Published: 2005
ASP.NET 2.0: A Developer's Notebook Authors: Wei Meng Lee, Pages: 326, Published: 2005
Microsoft Expression Web 2007 in Depth Authors: Jim Cheshire, Pages: 792, Published: 2008

Web:
ASP.NET 2.0 Master Page Problem However, I have not found a fix for the javascript! .... NET 2.0 master pages. Message: I was working on a problem with your menu when ...
JavaScript problem used in Master Pages and Subfolders the project clean but not able to do this until I fix the problem with JavaScript. I'm using a Master page in the project. Any suggestions? ...
Re: [AspNet2] using javascript in master page & content pages ... Sep 12, 2006 ... i have a master page in the main directory and content pages in a > folder...... .i have tried to put the javascript functions on the ...
Master Page Error from Exporting file from SharePoint Designer If you are using SharePoint Designer (SPD) to create a master page file that ... Adding Javascript file link in Master Page re: Adding Javascript file link in Master Page. Just had the same problem myself . Although your solution works I would prefer my script to be included in ...
MSDN how to call a javascript function from content page which was ... you can call the javascript within the page_prerender()...... event of your Masterpage. I had overcome with the same problem adding the Calendar to a ...
problem with javascript and master pages : clientscriptinclude, master Hi I have some code like this in my javascript document.getElementById('<%= Label1.ClientID%>').style.backgroundColor = 'red'; This works ...
Scriptmager Bug : Forms Authentication + MasterPage = Javascript ... I'm getting this annoying javascript error from the script manager ('syntax error on line 3') when I have a script manager on a master page ...
Problem with java script in master page - ITtoolbox Groups Problem with java script in master page. Your Full Name:. Your Email Address:. Recipient Email(s): Separate multiple addresses with commas. ...
Referencing JavaScript in ASP.NET MVC Master Pages Here's a quick tip on including JavaScript files in your MVC master page views. ... But wait! there's a problem with this. Depending on what route has led ...

Videos:
Gaia Gold Getter! Okay this is a program I found on the Underground section of a cheat site. I am sharing it with you guys. =] Alright, so what you do, after you ...




Search This Site:










forums???

dnn 308 users module error help please

control (decrease, limit) the speed (bandwidth) of downloading and uploading

wilson o/r mapper

control in control problems

i use htmlencode, but if the user name is sánchez he sees s&#225;nchez. how can i solve it?

how to validate fonts for a particular language?

low-impact logging

making a one off home page image (tabid=1)

how can i configure dnn to show rtl?

[resolved] panels side by side

requiredtextbox - composite control or inherit from textbox

why doesn't the ~/something.aspx work with stylesheets ?!?!

dnn 3.2.0 and the treeview

escaping client script blocks

how to retrive a picture from a database table column and display it in an image sever control

where can i get some ... stock photography?

preventing simultaneous logging

how to: prevent cross-site scripting in asp.net

upcoming changes to asp.net 2.0 in beta 2

skipping theme for one page

dnn e-commerce modules (ais-ec) release announcement: ais-ec 1.0.3

freeskin 4 y'all

container css problem

custom / compare validators

dnn 3.0, xhtml strict, tableless design & xhtmlwebcontrols...

javascript serverside

is there any way of doing this..

radio button event not firing

tabs control panel

 
All Times Are GMT