Includes and variables in .Net?!?

  • Thread starter Thread starter W1ld0ne [MCSD]
  • Start date Start date
W

W1ld0ne [MCSD]

I am working on a site that requires a peice of code to be on every page in a site. This code however requires that a variable is passed from the page to the code that is on every page.

In ASP you could use #Includes with variables declared above it ad used inside it.

I think I have conquered the include bit by creating a Custom User Control with the necessary functionality, which can then be "Included" on every page. My problem however is that I now need to pass a variable to the page. I can pick up QueryStrings from the page, but I do not want the variables to be publicly visible.

Steps I have tried to date:
1.. Create properties on the pages and try to read them from the included user control. This solutions can not work, since I would have to create the parent object. This means that I need to know its name, but the control must be usable from any pages. Me.parent.... I think must provide a way to do that, but I do not know how.
2.. Create properties on the control and set them from the page. This works, except that the properties are set only after the page is loaded. I need to possibly redirect or stop the rendering of the page, should the variable be incorrect. (I stuck the code into the page_onload event.)
Any suggestions would be greatly appreciated.

Thanks
David Taylor
 
Hi David,

I haven't explored this deeply.

How about declaring an Interface for your Pages which defines a method
that your UC can call from its constructor. This would happen pretty early on
in the Page's life, but I'm not sure if it will be early enough.

Public Sub New
DirectCast (UC.Parent, IWhatever).TheCallback (SomeValue)

Just a thought.

Regards,
Fergus
 
Back
Top