[Reprint] 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 not conducive to transplantation, for example, the current site address is http://www.xxx.net, if one day the site is more the http://www.xxx.com, then all the link addresses are invalid, need to change, 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. based on the root directory path: such as: <a href = "http://www.knowsky.com/xxx/xxx.gif"> such a solution in ASP. during net2.0 debugging, the virtual directory is not created and cannot be correctly displayed (I am not very 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.
. Hidebar
{
Height: 56px;
Width: 5px;
Cursor: hand;
Background-image: URL (.../../images/xxx.gif );
} Then, we only need to fill in hidebar in the cssclass of the corresponding elements and controls, so that every page inheriting masterpage or using user controls can correctly display images.
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.