0

Have a message that currently displays on every page of our website. I'd like to change this so that it only appears on the homepage which is default.aspx. Please let me know what I can try. the below code lives in the code behind of the master page of the site. We use vb.net but if someone can write it in C# I can convert it.

Previous code that displays label text on every page:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Using ds As DataSet = SystemDataObject.SystemDataGetMessage()
        lblSystemMessage.Text = ds.Tables(0).Rows(0)("SystemMessage_sd").ToString
End Using   

End Sub

Code I have written that isn't working, what am I missing?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Using ds As DataSet = SystemDataObject.SystemDataGetMessage()
    Dim appPath As String = Request.PhysicalApplicationPath
    If appPath = "/Default.aspx" Then
        lblSystemMessage.Text = ds.Tables(0).Rows(0)("SystemMessage_sd").ToString
    End If
End Using

End Sub
Servy
  • 202,030
  • 26
  • 332
  • 449
DalW
  • 59
  • 1
  • 1
  • 6
  • Have you tried using Request.Url and parse it to get "default.aspx" ? Here is another post :in c# http://stackoverflow.com/questions/593709/how-to-get-the-url-of-the-current-page-in-c-sharp –  Apr 06 '17 at 17:14
  • When you navigate to Default.aspx, does the lblSystemMessage.Text line of code get hit? – Seano666 Apr 06 '17 at 17:15
  • Haven't tried using request.url. Not really sure how to do that and not understanding what I'd then do with it? @Seano666 no the lblSystemMessage.Text is getting hit when I step through it. – DalW Apr 06 '17 at 17:22
  • Your answer to my question is unclear sorry, the code for setting the label IS getting executed? So then are you not seeing the label text on the page when it loads? – Seano666 Apr 06 '17 at 17:26
  • Sorry @Seano666 no when I step thru the code the lblSystemMessage.Text is not getting executed, it skips over to the End If. – DalW Apr 06 '17 at 17:34

1 Answers1

0

Ended up wrapping the control in a panel with ID of Message and using the following code to display only if on the homepage.

If Page.Title = "Home" Then
    Message.Visible = True
Else
    Message.Visible = False
End If
VDWWD
  • 35,079
  • 22
  • 62
  • 79
DalW
  • 59
  • 1
  • 1
  • 6