How to use IsFirstPage

Topics: Controls, Themes
Aug 28, 2008 at 11:02 PM
Is there a way that I can hide a control such as Tags only on the first page and show it on other pages? 

{Similar to Administration..where you use something like <% if (Page.User.Identity.IsAuthenticated) { %>..<%} %>

Thank you
-jw

Aug 29, 2008 at 9:37 PM
In site.master.cs

 

private bool m_pageMode = false;
public bool pageMode
{
get { return m_pageMode; }
set { m_pageMode = value; }
}

 

 

string szRoot = Utils.RelativeWebRoot + "default.aspx?";
if ((Request.RawUrl.ToLowerInvariant().Equals(szRoot)) || (Request.RawUrl.ToLowerInvariant().Equals(Utils.RelativeWebRoot)))
{
BlogEngine.Core.
Page front = BlogEngine.Core.Page.GetFrontPage();
if (front != null)
{
pageMode =
true;
}
}

Then in site.master..aspx

 

<%

if (!pageMode) { %>

If you want something different on all pages instead of posts, you also need something like 

 

if

((Request.RawUrl.ToLowerInvariant().Contains("/page/")) ||  (!string.IsNullOrEmpty(Request.QueryString["page"])))
{
pageMode = true;
}

 

Sep 17, 2008 at 9:42 PM
Hi:
Thank you for the tip.  I tried it and got this error..appears syntax related:
I have checked the brackets, tried a different "if" statement and it still points to the problem in that line
Any thoughts??
Thanks JW
Compiler Error Message: CS1519: Invalid token 'if' in class, struct, or interface member declaration

Source Error:


Line 29: 
Line 30: string szRoot = Utils.RelativeWebRoot + "default.aspx?";
Line 31: if ((Request.RawUrl.ToLowerInvariant().Equals(szRoot)) || (Request.RawUrl.ToLowerInvariant().Equals(Utils.RelativeWebRoot)))
Line


Sep 19, 2008 at 1:58 AM

There may be a subtle detail missing in what I extracted for the posting.  Below is the a larger section of the code this was taken from and that is currently working.

I also found that in debug mode the value was “default.aspx?” not “default.aspx”.

This code exists in the site.master.cs file.

Tim

      private bool m_pageMode = false;

      ///

      /// pageMode = true if /page/ in URL

      ///

      public bool pageMode

      {

            get { return m_pageMode; }

            set { m_pageMode = value; }

      }

      private bool m_isFrontPage = true;

      ///

      /// panelMode, true if printMode or pageMode

      ///

      public bool isFrontPage

      {

            get { return m_isFrontPage; }

            set { m_isFrontPage = value; }

      }

      protected void Page_Init(object sender, EventArgs e)

      {

                  CheckPage();

      }

      private void CheckPage()

      {

            pageMode = false;

            // Page is in the URL or Querystring

            if (Request.RawUrl.ToLowerInvariant().Contains("/page/"))

            {

                  pageMode = true;

            }

            if (!string.IsNullOrEmpty(Request.QueryString["page"]))

            {

                  pageMode = true;

            }

            string szRoot = Utils.RelativeWebRoot + "default.aspx";

            szRoot = szRoot.ToLowerInvariant();

            string url = Request.RawUrl.ToLowerInvariant();

            if (url.EndsWith("?"))

            {

                  url = url.Remove(url.Length - 1, 1);

            }

            // if IsFrontPage is set on one of the pages, assume we are in page mode

            // site/ site/default.aspx? site/default.aspx

            if ((url.Equals(szRoot)) || (Request.RawUrl.ToLowerInvariant().Equals(Utils.RelativeWebRoot)))

            {

                  BlogEngine.Core.Page front = BlogEngine.Core.Page.GetFrontPage();

                  if (front != null)

                  {

                        url = front.RelativeLink.ToUpperInvariant();

                        pageMode = true;

                        isFrontPage = true;

                  }

            }

      }

From: watkinsjz [mailto:notifications@codeplex.com]
Sent: Wednesday, September 17, 2008 4:43 PM
To: tstanley@tsisys.com
Subject: Re: How to use IsFirstPage [blogengine:34504]

From: watkinsjz

Hi:
Thank you for the tip. I tried it and got this error..appears syntax related:
I have checked the brackets, tried a different "if" statement and it still points to the problem in that line
Any thoughts??
Thanks JW
Compiler Error Message: CS1519: Invalid token 'if' in class, struct, or interface member declaration

Source Error:

Line 29: 
Line 30: string szRoot = Utils.RelativeWebRoot + "default.aspx?";
Line 31: if ((Request.RawUrl.ToLowerInvariant().Equals(szRoot)) || (Request.RawUrl.ToLowerInvariant().Equals(Utils.RelativeWebRoot)))
Line

Read the full discussion online.

To add a post to this discussion, reply to this email (blogengine@discussions.codeplex.com)

To start a new discussion for this project, email blogengine@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Sep 21, 2008 at 6:00 PM
I took a non-programatic approach to solving this problem.  I created a class called fullviewonly and added to anything that I didn't want to be displayed on the front page. 

Then I added the following syntax to the styles.css file:

    .posts .post .footer .fullviewonly {
        display: none;
    }

The trick here is that .posts.post is only present on the front page.  If you look at the actual post you will see that class="post" doesn't exist.  So when I am on the front page the css path .posts .post exits, and on the postview page the css path .posts .post doesn't exist.

Have a glance at my blog and you will see that I added the .fullviewonly class to the bits in the footer section that I didn't want shown on the front page...
Sep 21, 2008 at 6:19 PM
For a programatic way of determining the front page I used the following javascript:

      var rawUrl = location.href.toLowerCase();
      if(rawUrl.length == rawUrl.lastIndexOf("/")+1 || rawUrl.indexOf('default.') >=0)
      {
            // You are at the front page
      }

This can easily be converted to C# and used in your codebehind.  
Nov 29, 2008 at 5:45 PM
I converted it for c# and it appears to work.  Does anyone see a problem with this syntax?

// using System.Text.RegularExpressions;
if (Regex.IsMatch(Request.Path, "/$") || Regex.IsMatch(Request.Path, "default.", RegexOptions.IgnoreCase))
{
Response.Write("You are at the front page");
}