How to get inner html of page/control with datagrid and pass text back to client as string

M

moondaddy

I have a frame set where I have a hidden frame page used to marshal data
back and forth. In another frame who's source page needs to stay fixed and
not do round trips. However, at times I want do display a small table and
its row count will vary depending on the number of transactions taking place
in the client browser. I would like to execute a datagrid on the server and
capture the html generated, then pass that html as a string parameter back
to the client in this marshaling page. Then with a little jscript I could
place this string inside the inner html of a div element to display the
table. Is there a way to capture this html on the server?
 
M

[MSFT]

Hello,

Thank you for using the community. To get a control's HTML code on server
side, we can call its RenderControl method, to render its HTML code in a
HtmlTextWriter, and then get the string. Following is sample on this, hope
it help:


DataGrid dg= new DataGrid();

ArrayList al = new ArrayList();

al.Add("abc");

al.Add("ccc");

dg.DataSource =al;

dg.DataBind();


System.Text.StringBuilder sb= new System.Text.StringBuilder();

System.IO.StringWriter sw= new System.IO.StringWriter(sb);

HtmlTextWriter hw= new HtmlTextWriter(sw);

dg.RenderControl(hw);

Response.Write(sb.ToString() );

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
M

moondaddy

Thanks Luke this looks like what I will want. I'm writing this is vb.net
but understand most of what you have below with just one quesiton (so
far...), how does the line below work.

dg.RenderControl(hw);

can I write the html to a string variable that I would pass back in a hiden
control like a parameter or is that what the HtmlTextWriter is going to do?
 
M

[MSFT]

RenderControl method will output server control content to a provided
HtmlTextWriter object, and it only accept a HtmlTextWriter object as
paramter, not a string. For more detail information about this method, you
may refer to:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwebuicontrolclassrendercontroltopic.asp

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top