Setting user control custom class from parent page

Hi Experts

I have the following class in wuc_Test.ascx
public static class tblProps
    {
        public static string[] _arrH;
        public static string[] _arrC;
        public static class _ctlV
        {
            public static bool _blnV;
            public static int _posV;
        }
        public static class _ctlE
        {
            public static bool _blnE;
            public static int _posE;
        }
        public static class _ctlD
        {
            public static bool _blnD;
            public static int _posD;
        }
    }

Open in new window

On the aspx page, I have the directive:
<%@ Register src="wuc_Test.ascx" tagname="wuc_Test" tagprefix="uc1" %>

Open in new window

On the aspx.cs page, I'm adding the ascx dynamically:
protected void addWuc_Test()
    {
        wuc_Test wuc_Test1 = new wuc_Test();

        pnlPrnt.Controls.Clear();
        pnlPrnt.Controls.Add(wuc_Test1);
    }

Open in new window

how can I access the class from the aspx.cs page ? something similar to the following:
wuc_Test1.tblProps._arrH  = {};
wuc_Test1.tblProps._ctlV._blnV = true;

Many thanks.
Faraj1969System AdministratorAsked:
Who is Participating?
 
Kyle AbrahamsSenior .Net DeveloperCommented:
remove static from each of the classes, in your main class constructor create instances of the other classes, exposing them as properties.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Don't make the class static:
public class tblProps

in the ascx create an instance of the class, with a public property.
tblProps _tProp = new tblProps();

public tblProps tProp
{
get
{
   return _tProp ;
}
set 
{
   _tProp = value;
}
}

Open in new window


then in the aspx:
wuc_Test1.tProp._ctlV._blnV = true;
0
 
Faraj1969System AdministratorAuthor Commented:
In the aspx.cs, a red line under _ctlV and an error message says: '_ctlV': cannot reference a type through an expression.
0
 
Faraj1969System AdministratorAuthor Commented:
Many thanks mate, direct to the point.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.