Root Path Reference Syntax





Root Path Reference Syntax

Many of the server-side controls contain URL properties, such as the src attribute of the img control or the href property of the a control. There is a convenient syntax that you can use within a URL property of a server-side control to reference the root of your application directory to avoid hard-coding relative paths in your application's directory structure. The syntax is to precede the path with the tilde character (~), which at compile time is resolved to a reference to Request.ApplicationPath, as shown in Listing 2-12. Note that this syntax works only with server-side controls and cannot be used with regular HTML elements.

-12 Using Root Path Reference Syntax
<!— RootPathSyntax.aspx —>
<html>
<body>
<h1>Root path reference test page</h1>
<form runat="server">
<a href="~/otherpages/hi.aspx" runat="server">
<img runat="server" src="~/images/hi.gif"/>
</a>
</form>

</body> </html>

     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows