Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

C# Class Question

Good Morning All,

I have a basic question that should be pretty easy.  I have a class file that is a WebControl class file and in the OnInit I create a window object it is a telerik control RadWindow.  So that RadWindow has a ContentTemplate which is a ITemplate that I had to create a seperate class and use the ITemplate interface such as System.Web.UI.ITemplate.  In the instantiate of that I have all content controls I need etc.  I have a button in this template that has to go into the contenttemplate so it needs to exist here.   On the OnClick event handler I need to call the RadWindow property to close it RadWindow.VisibleOnPageLoad = false.   Stupid question is how do I call that from within the ITemplate when it is being created on the OnInit of my main class?  I tried doing such as this in the close button event:

MyMainClass mycls = new MyMainClass();
mycls.RadWindow1.VisibleOnPageLoad = false

but I am getting NULL for that RadWindow1 when I do this so I know it is the new I beleive.  Thanks all not sure why this is confusing me.
Avatar of santhimurthyd
santhimurthyd
Flag of United States of America image

Do you have initialied your Telerik control in the constructor of your class

e,g

class MyMainClass
{
 public RadWindow RadWindow1;
  public MyMainClass ()
 {
 RadWindow1 = new RadWindow();
 }

}

try with the above syntax
Avatar of sbornstein2
sbornstein2

ASKER

Well the RadWindow1 initlaization is happening actually in the OnInit because it is a WebControl

public RadWindow RadWindow1;
protected override void OnInit(EventArgs e)
{
RadWindow1 = new RadWindow();
}
then how should I call it in my other class?
OnInit of you UserControl will be called only when the control start rendered, So to access the control it's to be initialized first.

Nothing changing in call the control, it's matter of initialization.
I have to have the RadWindow in the OnInit though of the WebControl here is what I have:

public class MyControl : WebControl
{
    public RadWindow RadWindow1;
    private ContentInnerTemplate cntTemplate = new ContentInnerTemplate();
    protected override void OnInit(EventArgs e)
        {
                RadWindow1 = new RadWindow();
                RadWindow1.ContentTemplate = cntTemplate;
                this.controls.add(RadWindow1)
        }
}

I had to customize the contenttemplate so now the template is:
public class ContentInnerTemplate : System.Web.UI.ITemplate
    {

 public void InstantiateIn(System.Web.UI.Control container)
        {
            RadButton rbtnDone = new RadButton();
            rbtnDone.Click += new EventHandler(rbtnDone_Click);
            container.Add(rbtnDone);
        }

 protected void rbtnDone_Click(object sender, EventArgs e)
        {
            //THIS IS WHERE I WANT TO CALL THE RADWINDOW1 CLOSE
            RadWindow1.VisiblePageLoad = false;
        }
}
I have to have the Done button in the contenttemplate of the RadWindow in order to be able to get at the button.
ASKER CERTIFIED SOLUTION
Avatar of santhimurthyd
santhimurthyd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial