views:

100

answers:

1

While reviewing the demo project for the xVal, a validation framework for ASP.NET MVC, I noticed Masterpage javascript references were wrapped in an PlaceHolder control:

<asp:PlaceHolder runat="server">
    <script type="text/javascript" src="<%= Url.Content("~/scripts/jquery-1.3.2.min.js") %>"></script>
    <script type="text/javascript" src="<%= Url.Content("~/scripts/jquery.validate.js") %>"></script>
    <script type="text/javascript" src="<%= Url.Content("~/scripts/xVal.jquery.validate.js") %>"></script>
</asp:PlaceHolder>

I'm not sure I see the benefit of the PlaceHolder control over merely referencing the files directly:

<script type="text/javascript" src="/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.validate.js"></script>
<script type="text/javascript" src="/scripts/xVal.jquery.validate.js"></script>

What am I missing?

+1  A: 

Sometimes you only need the JS files on a single/few page(s). When that is the case it helps to only load them on the pages you need them, thus the placeholder. I've actually found myself having to do this quite a bit recently, and it definitely does help, at least in my case. If nothing else, it keeps things a little less cluttered.

dhulk
So, though there isn't this need per the demo application, it's probably the standard approach the author uses in case he needs to manage the references?
Ben Griswold
I agree that this is probably just the author's standard approach. I've noticed that PlaceHolders seem to respect white-space within their tags better than Panel controls, but I can't see how that would matter here. I suspect that at some point there was/is/will be some code to set Visible=False under certain conditions.
Ken Browning
No there isn't a need for it really. The more useful part of the code snippet you posted I'd say is the part that deals with resolving the URLs of the files.
dhulk
Interesting. It appears the PlaceHolder provides little to no value in this case. I agree with your answer regarding the possible advantages of using the PlaceHolder though (I've done it myself), @dhulk, so I'm marking your answer correct. Thanks.
Ben Griswold