473,385 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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?

--
mo*******@nospam.com
Nov 18 '05 #1
3 2208
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.)


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

--
mo*******@nospam.com
"[MSFT]" <lu******@online.microsoft.com> wrote in message
news:QN*************@cpmsftngxa06.phx.gbl...
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.)

Nov 18 '05 #3
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/de...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.)

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Oscar | last post by:
I am looking for a way to pass an ADO recordset that has been retrieved in an ASP page to another HTML-page. Is there someone who can provide me with a small sample or a link to see how this is...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
0
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
5
by: Brian Kitt | last post by:
I have a C# application that builds dynamic HTML and renders it. Because it is rendered in this way, the input controls are not server controls. I write the entire page, which has a variable...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
1
by: Andrew | last post by:
I'm adding this as it to me a while to figure out all the pieces to be able to do this without using Microsoft.Office.Interop which caused me problems on the web-server. Streaming is the easy...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.