Solved

Dynamically check if URL is an Application Page

Posted on 2013-01-25
4
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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