Master Page Best Practice

L

LaptopHeaven

When using Master Pages, what is the best Best Practice when it comes to
images and hyperlinks on the master page? Is it better to use WebControls
(<asp:Hyperlink/>), HtmlControls (<a href="~/somewhere.aspx"
runat="server">) or using ResolveClientUrl("~/somewhere") inline?
 
S

Steve C. Orr [MVP, MCSD]

I prefer the second option you mentioned for most situations.
<a href="~/somewhere.aspx"> runat="server">

It is optimal, giving as much functionality as is needed without any
additional overhead.
WebControls (such as Hyperlink) require more server resources than the
simple href, and the last option you mentioned is usually more of a
maintenance headache.
 
L

LaptopHeaven

Thanks. That what I was guessing.
How about handling the <script...></script> tag inside the <head>. The ~/
does not seem to work.
 
S

Steven Cheng[MSFT]

Hi Heaven,

Since client-side <script> tag can not be marked with "runat=server"(it
will make it be parsed as server-side code at compilation time), you can
consider embed some server code expression to render the dynamic resolved
path. For example:

==========================

<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" src="<%=
ResolveUrl("~/scripts/common.js") %>"></script>
...................
=========================

BTW, when using the above embeded code block in <head> section, it will
make the Page.Header.Controls collection no longer modifiable(add nor
remove subcontrols in it). Therefore, if you may consider move the script
block into other postion in page if this is the case.

Please feel free to let me know if you have any other concerns on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

AG

I thought that ~/ did not work with html controls.
Has this changed?

--

AG
Email: discuss at adhdata dot com
 
S

Steven Cheng[MSFT]

Hello Heaven,

Does the further suggestion help you resolved the problem? If you have any
other questions related, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top