468,792 Members | 1,701 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,792 developers. It's quick & easy.

Catching specific controls html output after render

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
Nov 18 '05 #1
4 1163
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.

Nov 18 '05 #2
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.

Nov 18 '05 #3
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);





"Jacob Yang [MSFT]" <ji***@online.microsoft.com> wrote in message
news:qT**************@cpmsftngxa07.phx.gbl...
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.

Nov 18 '05 #4
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.

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Steve Drake | last post: by
4 posts views Thread by Alexandre Soares | last post: by
4 posts views Thread by clintonG | last post: by
3 posts views Thread by Qwert | last post: by
3 posts views Thread by msnews.microsoft.com | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.