1

Just tried out VS2012 with the default template site and I'm totaly new to the concept how to include javascript and css. In the MasterPage the javascript seams to be included using the scriptmanager and scriptreference.

There are also some files like package.config.

Can someone explain how this is supposed to be used. How do I include my own javascript & css. How do I add a jquery ready() to the site.master?

0

1 Answer 1

1

To inculde a css file to your site add a link tag in the <head> section of your page, for javascript add a script tag.

<head>
    <link href="file.css" type="text/css" /> // This wil include your css file
     // For JavaScript
      <script src="jquery.js" type="text/javascript" ></script> // This wil include your java script file
     <script type="text/javascript" >
          // write Your JavaScript code here


         // For using jquery code, add jquery method inside the script tag, example below

         $("document").ready( {
               // your jquery code
           });

     </script>
</head>

Script manager is used for different purposes:

1) Using Ajax Controls

2) When we access web services in Client Side

3) Page Methods etc

From MSDN about ScriptManager:

You must use a ScriptManager control on a page to enable the following Microsoft Ajax features of ASP.NET:

Client-script functionality of the Microsoft Ajax Library, and any custom script that you want to send to the browser. For more information, see Creating Custom Client Script by Using the Microsoft Ajax Library.

Partial-page rendering, which enables regions on the page to be independently refreshed without a postback. The ASP.NET UpdatePanel, UpdateProgress, and Timer controls require a ScriptManager control in order to support partial-page rendering.

JavaScript proxy classes for Web services, which enable you to use client script to access Web services and specially marked methods in ASP.NET pages. It does this by exposing the Web services and page methods as strongly typed objects.

JavaScript classes to access ASP.NET authentication, profile, and roles application services.

Sign up to request clarification or add additional context in comments.

2 Comments

The template includes the jquery in the script manager so if I use your approch I include my script before the jquery and then I cant use jquery... Or do I misunderstand something?
@ahrberg if your include your script inside scriptmanager -> scripts tag, this will only include your jquery file. In order to use jquery in your page, first you have to add the jquery file using script tag and then you will write you jquery code inside the script tag as I mentioned in my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.