VB.NET display label text only on default.aspx page only

时间:2017-04-06 17:11:45

标签: asp.net vb.net

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

1 个答案:

答案 0 :(得分:0)

结束将控件包装在ID为Message的面板中,并使用以下代码仅显示在主页上。

Mail2/Inbox/email2