Solution to the image path in ASP. NET masterpage!

Source: Internet
Author: User
Generally, there are three methods to express the link path: absolute path, relative path, and root directory-based path. In addition, for ASP. NET Server controls, you can also use "~" To replace the root directory.
In masterpage and user controls, images are often used as backgrounds or beautiful buttons. However, when you specify the SRC or background of an image, errors often occur due to link paths.
1. Use absolute path: an absolute file path like "D: \ XXX \ xxx.gif" is generally not desirable. You can consider using the URL method to write it as http: // xxxx/XX/xxx.gif ". But the disadvantage is that it is not conducive to transplantation, such as the current site The address is a http://www.xxx.net, and if one day the site updates the http://www.xxx.com, all the link addresses are invalid and need to be changed, making it difficult to maintain.
2. use relative path: Use the path relative to the page location, such as ".. \ images \ xxx.gif ", so that the masterpage and user control can be correctly displayed, but if the page inheriting masterpage is put in a different folder, or the page using the user control is not in the same folder, the correct image location will not be found on this page!
3. The path based on the root directory is like:<A href = "/XXX/xxx.gif">When debugging ASP. net2.0, this solution cannot be correctly displayed because no virtual directory is created (I am not sure, I did not confirm ^_^ ). "~" Cannot be used on HTML Tag elements of non-server controls. To specify the path.
So what should we do to make the image visible during design? I used CSS to do this. For the elements and controls to display the image, we can write a simple CSS to locate the image, because the position of the CSS file is generally not changed (in app_theme/themename/xxx.css ), this method also works.
Next, we only need to fill in hidebar in the cssclass of the corresponding elements and controls, so that each page that inherits masterpage or uses user controls can correctly display images.
I think there should be other better methods, and I hope someone can give me some advice. . Hidebar
{
Height : 56px ;
Width : 5px ;
Cursor : Hand ;
Background-Image : URL (../images/xxx.gif) ;
}
Related Article

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.