By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,744 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Includes and variables in .Net?!?

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.