79403124

Date: 2025-01-31 15:01:12
Score: 3.5
Natty:
Report link

Thanks for responding. However, although the syntax is accepted, I can only get this working on the master page itself...

Master Page

Public Class Site
Inherits System.Web.UI.MasterPage

Public SiteIdentifier As Integer

Private Sub Site_Init(sender As Object, e As EventArgs) Handles Me.Init
    SiteIdentifier = IIf(System.Web.HttpContext.Current.Request.UserHostAddress.Substring(7, 2).ToString = "20", 20,
                     IIf(System.Web.HttpContext.Current.Request.UserHostAddress.Substring(8, 2).ToString = "20", 20,
                     IIf(System.Web.HttpContext.Current.Request.UserHostAddress.Substring(7, 2).ToString = "40", 40,
                     IIf(System.Web.HttpContext.Current.Request.UserHostAddress.Substring(8, 2).ToString = "40", 40,
                     IIf(System.Web.HttpContext.Current.Request.UserHostAddress.Substring(7, 2).ToString = "60", 60,
                     IIf(System.Web.HttpContext.Current.Request.UserHostAddress.Substring(8, 2).ToString = "60", 60,
    60))))))
End Sub

End Class

Child Page

Public Class SearchConsignments
Inherits System.Web.UI.Page
Dim MySite As Site = Me.Master

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     Me.txtTest.Text = MySite.SiteIdentifier.ToString
End Sub

Any attempt to use the master page variable on a child page gives the error "Object reference not set to an instance of an object."

Any ideas where I'm going wrong? Thanks.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): Any ideas
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: steve_flynn