Catching specific controls html output after render

  • Thread starter Thread starter Ron Vecchi
  • Start date Start date
R

Ron Vecchi

In the RenderControl() method I have some code which will catch the controls
HTML output. But what I'm tring to accomplish is catching only a perticular
control and its child controls. The code below catches everything.

----------------------------------------------------
string content "";

foreach(Control c in this.Controls) {
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
c.RenderControl(htw);
StringBuilder sb = sw.GetStringBuilder();
content += sb.ToString();
}
-----------------------------------------------------

The control has two placeholders each with an infiniat ammount of child
controls, lets say PlaceHolder1 and PlaceHolder2.
I would like to loop through the controls and catch all of the child
controls of PlaceHolder1 and store the output in a string. And then catch
all of the child controls of PlaceHolder2 and store the output in a
seperater string. I was able to add an if statement that checked for the
controls ID and if it was equal to one of the two PlaceHolder ID's then it
would catch the output(none). But wouldn't catch the PlaceHolders child
controls.


Any suggestions?

Thanks
Ron Vecchi
 
Hi Ron,

Thank you for posting to the MSDN newsgroups.

I am interested in this issue and researching on it now. More time is
needed. Thank you for your understanding.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Ron,

I am trying to reproduce the problem on my side. Would you please tell me
how to reproduce it step by step? I certainly appreciate your time.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks Jacob for your help,


I think I have it. Im not sure what I was doing before but I am catching
the control(and child controls now)
I supressed the base.RenderChildren
And am only writing out the content of placeholder 1
The I allow the content of any other controls written.

This is exactly what I was trying to do. I can't figur out what I was tring
before because I had checked for the PlaceHolders ID. Error on my part
somewhere anyways.

Thanks for your great support!
My code for override RenderChildren is below.
-------------------------------------------
string content1 = "";
string content2 = "";
string otherControls = "";

foreach(Control c in this.Controls) {
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
c.RenderControl(htw);
StringBuilder sb = sw.GetStringBuilder();

if(c.ID=="PlaceHolder1"){
content1 += sb.ToString();
}
else if(c.ID=="PlaceHolder2"){
content2 += sb.ToString();
}
else{
otherControls += sb.ToString();
}
}
writer.Write(content1);
writer.Write(otherControls);
//base.RenderChildren(writer);
 
Hi Ron,

I am very glad to know that the problem is resolved.

If you have any more concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top