473,765 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Strin gWriter
Dim TS As New HtmlTextWriter( W)
Dim S as String
Table.RenderCon trol(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 1476
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******** ******@TK2MSFTN GP09.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.Strin gWriter
Dim TS As New HtmlTextWriter( W)
Dim S as String
Table.RenderCon trol(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.Str ingBuilder sb = new System.Text.Str ingBuilder();
System.IO.Strin gWriter sw = new System.IO.Strin gWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter( sw);

tb.RenderContro l(htw);

Response.Write( "<br>" + HttpUtility.Htm lEncode(sb.ToSt ring()));

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
2805
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 assigned the task of extracting content from a given HTML page. If anyone's familiar with the Yahoo! Store order confirmation screen, I need to be able to grab the total amount from the table to the right-hand side. (Sample File:
1
1150
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 database. It is a table with 5 rows. Thanks in advance. Thanks in advance
1
6025
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 file is found, it just returns null atm. I would now like to alter it so that if the XML file is not found, some HTML is sent to the webcontrol instead. The problem with this is that I cannot return Html because the public method is XmlDocument,...
2
11521
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 page-design or even worse attacking my site with javascript directives i use stuff like (WebControls.Label)Output.Text = HttpUtility.HtmlEncode(userDefinedData); and my own functions which allow Line-Breaks and handle links. But that way seems not to be...
17
2494
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 'Button19' of type 'Button' must be placed inside a form tag with runat=server Can the IDE not do what it is supposed to do. It seems that it is a fight to make it do anything or did I do something wrong? It would seem silly to have to create a...
5
3595
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 that for server control component , code is running on the server side. But if I take as example a Label. I place on a webform an HTM label control and a WebForm label control, I could see that properties are different for
3
1594
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 want to navigate to in the bin folder along with the exe. I then put the following line in the load of my application: Me.webControl.Navigate(".\summarypage.html")
2
12349
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 passwords expiring within various periods of time. After sending mail to the users, I want to send a report to the help desk with a table of users included. It seems to me that the easiest way to do it is to convert the DataTable to HTML. ...
3
16920
by: Johny | last post by:
Does anyone know about a good regular expression for URL extracting? J.
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.