What code segment should you use to override the CreateChildControls method to accomplish this?

You are developing a custom control named ProductsGrid that will be used in the redevelopment of Domain.com’s e-Commerce Web applications. The ProductsGrid control contains a TextBox control and a DropDownList control that allows for the editing of product descriptions. The code for the ProductsGrid control is shown in the following exhibit.

[ParseChildren(True)]
public class ProductsGrid : Control, INamingContainer {
private Desc _desc;
private ITemplate _descTemplate;
public Desc Desc
{
get{return _desc;}
set{_desc = value;}
}
[TemplateContainer(typeof(DescTemplateContainer))] public ITemplate DescTemplate
{
get{return _descTemplate;}
set{_descTemplate = value;}
}
protected override void CreateChildControls()
{
// TO DO
}
}
public class DescTemplateContainer : Control, INamingContainer {
private Desc _desc;
public DescTemplateContainer(Desc desc)
{
_desc = desc;
}
public Desc Desc
{
get { return _desc;}
set { _desc = value;}
}
}
You need to ensure that the content specified in the DescTemplate() property is rendered by the ProductsGrid control. You need to override the CreateChildControls method to accomplish this.
What code segment should you use?

You are developing a custom control named ProductsGrid that will be used in the redevelopment of Domain.com’s e-Commerce Web applications. The ProductsGrid control contains a TextBox control and a DropDownList control that allows for the editing of product descriptions. The code for the ProductsGrid control is shown in the following exhibit.

[ParseChildren(True)]
public class ProductsGrid : Control, INamingContainer {
private Desc _desc;
private ITemplate _descTemplate;
public Desc Desc
{
get{return _desc;}
set{_desc = value;}
}
[TemplateContainer(typeof(DescTemplateContainer))] public ITemplate DescTemplate
{
get{return _descTemplate;}
set{_descTemplate = value;}
}
protected override void CreateChildControls()
{
// TO DO
}
}
public class DescTemplateContainer : Control, INamingContainer {
private Desc _desc;
public DescTemplateContainer(Desc desc)
{
_desc = desc;
}
public Desc Desc
{
get { return _desc;}
set { _desc = value;}
}
}
You need to ensure that the content specified in the DescTemplate() property is rendered by the ProductsGrid control. You need to override the CreateChildControls method to accomplish this.
What code segment should you use?

A.
if(this.DescTemplate = = null)
{
this.Controls.Clear();
DescTemplateContainer templateContainer = new DescTemplateContainer(_desc); this.Controls.Add(templateContainer);
}

B.
if(this.DescTemplate = = null)
{
this.Controls.Clear();
DescTemplateContainer templateContainer = new DescTemplateContainer(_desc); this.DescTemplate.InstantiateIn(templateContainer); this.Controls.Add(templateContainer);
}

C.
if(this.DescTemplate ! = null)
{
this.Controls.Clear();
DescTemplateContainer templateContainer = new DescTemplateContainer(_desc); this.Controls.Add(templateContainer);
}

D.
if(this.DescTemplate ! = null)
{
this.Controls.Clear();
DescTemplateContainer templateContainer = new DescTemplateContainer(_desc); this.DescTemplate.InstantiateIn(templateContainer); this.Controls.Add(templateContainer);
}

Explanation:
You must first determine that the DescTemplate property has returned content and then render the content. You can accomplish this by creating an instance of DescTemplateContainer that holds the content and then add the container to the ProductsGrid control for rendering.

Incorrect Answers:
A, B: If the DescTemplate property has returns a null reference then it has no content to render.
C: You need to call the InstantiateIn method of DescTemplate to place the template in the container.



Leave a Reply 0

Your email address will not be published. Required fields are marked *