can a user control get to the global.asax file?

Results 1 to 3 of 3

Thread: can a user control get to the global.asax file?

  1. #1
    Join Date
    Dec 1969

    Default can a user control get to the global.asax file?

    I've created a navigation user control that needs to figure out what page it's on and get some variables from the global.asax file. I've got things working for getting the current page, but I'm not sure how to get to the global from where I'm at. For example, to get to the servervariables for the page, I can just do HttpContext.Current.Request.ServerVariables["URL"], but what heirarchy do I use for the global? I've tried a few different things but can't seem to get it. Thanks.

  2. #2
    Join Date
    Dec 1969

    Default variables in the global?

    what you want to do is have a class which derives System.Web.UI.Page and store all your variables in there that are needed at the page level, like current user, maybe some other things...<BR><BR>then you derive all of your web pages from this class... say your new class is named "AWebPage" although that&#039;s a really stupid name, instead of deriving your web pages from System.Web.UI.Page , you&#039;d derive from YourAppNameSpace.AWebPage<BR><BR>of course, you&#039;d make those variables have public accessor methods so your web user controls can access them<BR><BR>hope this helps...

  3. #3

    Default RE: variables in the global?

    It really depends on what you want to do.<BR><BR>I doubt you would want to restrict the use of your control to one base class.<BR><BR>If you want a predictable interface on a Page class or on the Global class you should use an interface.<BR><BR>You can access the Global (System.Web.HttpApplication) using <BR>HttpContext.Current.ApplicationInstance.<BR><B R>You can cast this with an interface.<BR><BR>IMyInterface myInterface= (IMyInterface)HttpContext.Current.ApplicationInsta nce;<BR>myInterface.interfaceMethodOrProperty<BR>< BR>The same interface priciple applies to a Page class, why bind to a specific implementation, when you will need to cast to get custom properties anyway.<BR><BR>MyBasePage myBP = (MyBasePage)Page;<BR>myBP.MethodOrProperty<BR>vs.< BR>IMyBasePage myBP = (IMyBasePage)Page;<BR>myBP.MethodOrProperty<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts