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
Solved

Dynamically check if URL is an Application Page

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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