Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Accessing web control from a class -- d.o.t.d.

I've long ago discovered how to access control properties and methods from other controls, but never needed to access those properties and methods from a component class.

Say I'm in a control and need to call a method of another control:

C_CntrlClass uc_cntrlid = (C_CntrlClass) Page.FindControl("uc_cntrlid");
uc_cntrlid.Method(param);

But what about calling that same Method from a class component?  Since the class does not inherit the Web.UI.Page class, it does not expose the Page object.  This is where the IHttpHandler object comes in:

System.Web.UI.Page pg = (System.Web.UI.Page) System.Web.HttpContext.Current.Handler;
C_CntrlClass uc_cntrlid = (C_CntrlClass) pg.FindControl("uc_cntrlid");
uc_cntrlid.Method(param);

From the MS-HELP IHttpHandler documentation:  "HTTP handlers give you a means of interacting with the low-level request and response services of the IIS Web server and provide functionality much like ISAPI extensions but with a simpler programming model."

Here's the google thread which pointing me in the right direction, with special thanks to Kevin Spencer's comments.

Comments (0) | Post RSS RSS comment feed

Posted on 6/20/2003 8:53:00 PM by Dave Burke
Categories:
Tags: no tags for this post

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke