We help IT Professionals succeed at work.

C# Class Question

sbornstein2
sbornstein2 asked
on
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.
Comment
Watch Question

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

Author

Commented:
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();
}

Author

Commented:
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.

Author

Commented:
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;
        }
}

Author

Commented:
I have to have the Done button in the contenttemplate of the RadWindow in order to be able to get at the button.
Check this Url on how to use the Webcontrol and ITemplate

http://msdn.microsoft.com/en-us/library/aa478964.aspx

Your requirment can be approached wih the cusotm driven event, let me try some sample and share with you