Oct 13, 2006 04:29 PM|awjenning|LINK
I have a class method which calls FindControl and creates a generic control reference as follows:
Control oControl = oCriteriaTable.FindControl(sControlName);
The generic oControl variable may end up containing a reference to a normal form control (e.g. Textbox, DropDownList) or it may end up with a reference to a UserContol (e.g. csiDateRange)
For Textbox or DropDownList Controls I can access the generic control's properties by casting as follows:
sControlValue = ((TextBox)oControl).Text;
sControlValue = ((DropDownList)oControl).Text;
The problem I am having is that I cannot figure out how to cast when a UserControl is in the generic so that I can get to it's custom properties.
If this code is contained in an ASP page I can cast as follows:
sControlValue = ((ASP.csiDateRange)oControl).SomeCustomProperty;
However..... This code is contained in a regular class file not an ASP page. The (ASP.csiDateRange) cast fails to compile because the ASP namespace is unknown. How do I reference that namespace (and that of my UserControl) in my class?
I have the follow using directives for the class:
The UserControl Control Directive is as follows:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="csiDateRange.ascx.cs" Inherits="UserControls_csiDateRange" Classname="csiDateRange"%>
Please note again that the (ASP.csiDateRange) works perfectly in an ASP page, Just not in a regular class definition.