views:

90

answers:

1

I'm using RenderControl(writer) on a set of ASP.NET controls to get the generated server control markup back, for a template. These are form controls, such as radioboxes, input boxes, checkboxes.

The problem with this is the control's Parent.UniqueId is not set at this point, not Parent.Parent and so on. This means that the name="" attribute is never set, breaking the ViewState.

Is there any way to generate server control markup, and have the naming intact so that the ViewState will automatically work?

A: 

Create your control in this event, in this viewstate will automatically maintain.

protected override void CreateChildControls()
{   
  // create your control here.....
}

you should have to create your control in CreateChildControls to maintain viewstate of control during postback... this is the best approach when you creating your control at runtime.. you don't need to maintain viewstate manually.... these control treat same like other controls on the page and available.

Muhammad Akhtar
I tried this but it no baring on ParseControl and RenderControl(). I'm using ParseControl(text) where text has been generated from textBox.RenderControl(mywriter)
Chris S