Solved

Dynamically check if URL is an Application Page

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

16 Experts available now in Live!

Get 1:1 Help Now