ASP. net2.0masterpage usage tips

Source: Internet
Author: User
I haven't updated my blog for a long time. I want to write a summary of some tips on masterpage. I have encountered problems in my actual work.-> solve the problem and find out, if you have a better method, you can directly point it out.
1. Usage of masterpage and frameset: many posts on the Internet argue whether masterpage or frameset is used. I think the system of the navigation tree is still frameset, especially when the number of navigation trees is very complex, although. NET 2005 does not support its visual design. You just need to write your own HTML. In fact, masterpage is extended from usercontrol and is nothing new. masterpage refreshes the entire page every time, low productivity.
2. About the reference of JavaScript and CSS in masterpage: if all the pages applying the template are in the same path, this problem does not exist, but in practice, to facilitate management, some folders are often created, and the pages of the referenced template are placed in different files and added. In this case, the JS and CSS files referenced in the template are due to Path Problems, it may not be useful when applied to pages. You can use the following method to dynamically Add references to JS and CSS files in masterpage:
Method 1:

String jsfile = "<script language = \" javascript \ "src = \" {0} \ "type = \" text/JavaScript \ "> </SCRIPT> ";
Response. Write (string. Format (jsfile, resolveurl ("~ /JavaScript/jquery. js ")));

This method can solve the problem quickly, but response. write is the beginning of writing a script reference to HTML, which breaks the XHTML format and brings various risks. Remember when we did this in the past, at the same time, when I used Asp.net Ajax for development, I found ASP. net Ajax ajaxcontroltoolkit does not work. Later, it was found that response was used. write results.
Method 2:
 

String jsfile = "<script language = \" javascript \ "src = \" {0} \ "type = \" text/JavaScript \ "> </SCRIPT> ";
Page. header. innerhtml = string. Format (jsfile, resolveurl ("~ /JavaScript/jquery. js "));

This method can also be implemented and can effectively solve problems in the method.
Method 3:

Htmllink link = new htmllink ();
Link. href = string. Format (jsfile, resolveurl ("~ /CSS/base.css "));;
Link. attributes ["rel"] = "stylesheet ";
Link. attributes ["type"] = "text/CSS ";
Page. header. Controls. Add (Link );

This is a method for registering styles.
In addition, we recently discovered a method for registering client scripts, which is combined with the scriptmanager control in ASP. NET Ajax. I believe many people know it as follows:

<Asp: scriptmanager id = "scriptmanager1" runat = "server">
<Scripts>
<Asp: scriptreference Path = "~ /JS/jquery. js "/>
</Scripts>
</ASP: scriptmanager>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.