Solved

Dynamically check if URL is an Application Page

Posted on 2013-01-25
4
447 Views
Last Modified: 2013-01-25
I have some jQuery files loaded into my custom master page that are causing problems with my Application Pages. I want to dynamically check if the current URL is an Application Page and if so then omit some jQuery scripts.
For instance, I have this jQuery script in my master page
<script type="text/javascript" src="/_layouts/styles/branding/js/jquery-1.8.0.min.js"></script>

Open in new window

But if I navigate to an Application Page on my site then I want to conditionally check and then omit/remove the script from running, such as this code ...
<asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server">
	<%
    if(!web.Url.Contains("http://abcdev/_layouts") == true)
    {
    <script type="text/javascript" src="/_layouts/styles/branding/js/jquery-1.8.0.min.js"></script>
    }
    %>
	</asp:ContentPlaceHolder>

Open in new window

Unfortunately, this code does not work so I am looking for a good, working solution.
Thanks.
0
Comment
Question by:vpit
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 38820113
Hi,
I have currently no dev system at hand, but I think you should use
if (this.Request.Url.AbsoluteUri.Contains("/_layouts") == false)

Open in new window


HTH
Rainer
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38820137
On Masterpage add your script tag inside another ContentPlaceHolder in the <head>
e.g.

<asp:ContentPlaceHolder id="head" runat="server">
         <script type="text/javascript" src="/_layouts/styles/branding/js/jquery-1.8.0.min.js"></script>
</asp:ContentPlaceHolder>

Open in new window


On the ApplicationPage where you don't want that script just add an empty contentplacehoder. It will ignore anything inside the above masterpage placeholder.

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

Open in new window

0
 

Author Comment

by:vpit
ID: 38820279
Here is my final working example:
<asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server">
    
	<%
    if (this.Request.Url.AbsoluteUri.Contains("/_layouts") == false)
    {
    Response.Write("<script type='text/javascript' src='/_layouts/styles/branding/js/jquery-1.8.0.min.js'></script>");
    }
    %>
	</asp:ContentPlaceHolder>

Open in new window

0
 

Author Closing Comment

by:vpit
ID: 38820283
Excellent, thank you. See my last comment posting for the final code used.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now