473,408 Members | 2,839 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,408 software developers and data experts.

Extracting HTML from a WebControl

Hi,

I have created a Table webcontrol dynamically using code. Before rendering
it, I need to get at the HTML and do a couple of things manually. I've
tried a couple of methods to extract the HTML but things aren't working as
expected.

Dim W As New System.IO.StringWriter
Dim TS As New HtmlTextWriter(W)
Dim S as String
Table.RenderControl(TS)
W.Write(S)

When I run this, S = nothing, but the table renders fine on the page.

Any ideas?

Thanks,

Russ



Nov 18 '05 #1
2 1461
Russ,

Why do you need to extract the HTML? There may be another way to achieve
what you want without doing this.

Toby Mathews

"Russ" <ru**@UKS.com> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl...
Hi,

I have created a Table webcontrol dynamically using code. Before rendering it, I need to get at the HTML and do a couple of things manually. I've
tried a couple of methods to extract the HTML but things aren't working as
expected.

Dim W As New System.IO.StringWriter
Dim TS As New HtmlTextWriter(W)
Dim S as String
Table.RenderControl(TS)
W.Write(S)

When I run this, S = nothing, but the table renders fine on the page.

Any ideas?

Thanks,

Russ


Nov 18 '05 #2
Hi Russ,

As for getting the output html of a webcontrol, the code you used is
correct , just one thing missed. We need to use a StringBuilder to
construct the StringWriter and after rendering the control into the
HtmlTextWriter, we cna get the control's output in the StringBuilder. For
example:

=========================================
Table tb = new Table();
tb.ID = "tbl";
tb.Rows.Add(new TableRow());
tb.Rows.Add(new TableRow());
tb.Rows[0].Cells.Add(new TableCell());
tb.Rows[1].Cells.Add(new TableCell());

System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);

tb.RenderControl(htw);

Response.Write("<br>" + HttpUtility.HtmlEncode(sb.ToString()));

htw.Close();
sw.Close();
==================================

In addition, it is ok to retrieve the outputhtml of a control, however,
haven't means to easiliy replace the ouput which will be rendered in the
page. If you want to make some customizing on the control's output, it's
better that we override the control. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

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

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #3

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

Similar topics

1
by: Cognizance | last post by:
Hi gang, I'm an ASP developer by trade, but I've had to create client side scripts with JavaScript many times in the past. Simple things, like validating form elements and such. Now I've been...
1
by: Danny | last post by:
I am using the webcontrol in access to download links and it is nice. But do you know if there is a way to extract specific tags? I need to extract data from a table in a web page and into a...
1
by: anthonysmales | last post by:
I have a webservice which implements a webmethod called PrettyXML. This webmethod loads an XML file and returns the XML, which is then displayed in a webcontrol (textbox) on a webform. If no XML...
2
by: ViperDK | last post by:
What is the best way for that? I store all Data in the original form in the Database. To prevent output fields (especially the fields everyone can use) to do bad things like killing the...
17
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
3
by: Carl Gilbert | last post by:
Hi I have a Windows WebControl on my form and I plan to burn the application to a CD. The applcation has to navigate to a page that I am keeping in the root of the CD. I have put the page I...
2
by: Bob Weiner | last post by:
This is most likely a trivial question but I'm having a hard time finding an example. I am writing a script using C# 1.1 which iterates over AD accounts and builds a DataTable for those with...
3
by: Johny | last post by:
Does anyone know about a good regular expression for URL extracting? J.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.