2.6 Root Path Reference Syntax


2.6 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.

Listing 2-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> 


Essential ASP.NET with Examples in Visual Basic .NET
Essential ASP.NET with Examples in Visual Basic .NET
ISBN: 0201760398
EAN: 2147483647
Year: 2003
Pages: 94
Authors: Fritz Onion

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net