Solved

Dynamically check if URL is an Application Page

Posted on 2013-01-25
4
478 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
abstract class C# 1 35
Getting unexpected token error while consuming web service in sharepoint 13 27
Problem to copy file 14 42
Web page design problem 3 9
Microsoft SharePoint Foundation 2010 and Microsoft SharePoint Server 2010 do not offer the option to configure the location of the SharePoint diagnostic trace log files during installation.  This can, however, be configured through Central Administr…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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