page 1 of 1
Comments: 0 | Views: 2129
Hey guys,

i wrote a little custom web control so i can reuse it in my project, basically it has a bunch of div's and labels etc, and then normally within the main div, it should be capable of storing any normal HTML makrup of control, so i was researching and discovered i need to set the ParseChildren attribute to false and override AddParsedSubObject and CreateChildControls, however, for the AddParseSubObject method, i have to go check specifically the type of controls, otherwise they wont render correctly, my question is, how do u handle all the web controls, ill show u some code:


protected override void AddParsedSubObject(object obj)

{

if (obj is LiteralControl)

{

this.ViewState["InnerContents"] = ((LiteralControl)obj).Text;

}

else if (obj is Repeater)

{

mRepeaters.Add((Repeater)obj);

}

else if (obj is DataList)

{

mDataLists.Add((DataList)obj);

}

else if (obj is WebControl)

{

mWebControls.Add((WebControl)obj);

}

else

{

base.AddParsedSubObject(obj);

}

}

protected override void CreateChildControls()

{

if (mRepeaters.Count > 0)

{

foreach (Repeater repeater in mRepeaters)

{

PaneContents.Controls.Add(repeater);

}

}

if (mDataLists.Count > 0)

{

foreach (DataList dataList in mDataLists)

{

PaneContents.Controls.Add(dataList);

}

}

if (mWebControls.Count > 0)

{

foreach (WebControl webControl in mWebControls)

{

PaneContents.Controls.Add(webControl);

}

}

}


As you can see it seems a little cumbersome, adding a type everytime i want to support a control, PaneContents is the div which i want to add the control to.

I would of thought just checking WebControl and LiteralControl should suffice, but it doesn't.


My main objective is to achieve:


<cc:MyControl runat="server" ID="test">

//markup or Webcontrol here...

</cc:MyControl>



Thanks guys

page 1 of 1
Comments: 0 | Views: 2129
Microsoft Communities