Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Event Handlers - Sharing code

Status
Not open for further replies.

chewza

MIS
Feb 15, 2003
22
ZA
Hi there,

I have written code to automatically assign event handlers to controls of a certain type, at runtime - using "Addhandler".

I would like to use this same code for other pages, and am battling to do this. I have created a separate class for shared code, but cannot get this code to function properly in this environment.

The code for adding delegates, as well as the event handling code itself, loops through controls on the page.
The context of the current page, and the objects on it, need to be accessible.

This no longer works when I put the code into a class, and refer to it from my code behind page. I think the scope of the current page is lost..?

Any ideas? Any ways where this code can be shared amongst multiple pages?


Thanks for your time!

 
You can grab the scope of the current page from witrhin a class using the HttpContext Class. e.g. (C#)
Code:
HttpContext context = HttpContext.Current;
context.Response.Write("Hi");
the above would write to the response stream of the current page from a class. This will probably solve all your problems. However another approach maybe to encapsulate all this functionality in a master page and make each pageof your application inherit that page...

hope this helps

Rob


Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top