Solved

Reading pages HTML into Codebehind using VB.NET

Posted on 2004-10-19
17
1,124 Views
Last Modified: 2010-08-05
Hi,

I have an <TD> element on my aspx page.  I want to read all the HTML between this elements begin and end tag into my VB.NET code behind page so I can manipulate it and then output it back to the source as the new HTML.  How do I do this.  Is there an HTMLReader as there is an HTMLWriter.  

Thanks...
0
Comment
Question by:RaisinJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +4
17 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12347074
Hi RaisinJ,

actually there is no such objects like HTMLReader or writer
what is your approach ? you can redesign your page direct at design time or use dynamically creates controls    

Regards!
B..M
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 12347089
0
 
LVL 6

Author Comment

by:RaisinJ
ID: 12347103
mmarinov, what do you mean there is not such object as an HTMLWriter.  I've used it in ASP.NET to render Custom Web Controls.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:mmarinov
ID: 12347124
RaisinJ,

i don't know to exist of such object, searched for it in MSDN and didn't find anithing
may be it is some third parti object -

B..M
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12347144
RaisinJ,

You can make your table RunAsServer Control ( by right clicking the table & selecting RunAsServer)

& then you can access InnerText/InnerHtml like following in your codebehind

Table1.Rows[0].Cells[0].InnerText = "TEST";
Table1.Rows[0].Cells[0].InnerHtml = "TEST";


-tushar
0
 
LVL 6

Author Comment

by:RaisinJ
ID: 12347277
mmarinov, the objects name is HTML32TextWriter....

I'll try and be more specific with my question...  Here is what I have on my page...

The actual ASP.NET control is a datagrid.  I am trying to dynamically change an Image ()"><img src='Images\CheckMark.gif' border='0px'>) contained in my <td> element, based on another field in the Datagrid which is not visible.  I am handling this on the "Item_Created" event of the DataGrid.

Once the Datagrid renders into HTML, the output looks like this...

<td class="Status" id="h0_0"><a href="javascript:__doPostBack('DataGrid$_ctl2$_ctl0','')"><img src='Images\CheckMark.gif' border='0px'></a></td>

(I do not want to handle this with Javascript!)

I want my new output to look like this:

<td class="Status" id="h0_0"><a href="javascript:__doPostBack('DataGrid$_ctl2$_ctl0','')"><img src='Images\Error.gif' border='0px'></a></td>

Note, I would just be changing the CheckMark.gif to the image Error.gif, everthing else would remain the same.  I figured, if I could somehow read the HTML back into VB.NET, I could perform a simple "Replace" statement, and put the HTML back.

0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12347333
RaisinJ,

why don't you use ItemDataBound event of the datagrid, and depends on the value in a cell ( doesn't matter that the column is not visible ) change the imageurl of the image object ?

B..M
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 12347497
Rather easy

Add a runat="server" attribute to the TD element and an ID.
<td runat="server" id="tdMyEl">
...
</td>

In your codebehind you can declare the element like
Protected tdMyEl as System.Web.UI.HtmlControls.HtmlTableCell

Now you can use tdMyEl to manipulate any of the underlying Controls. If you want to manipulate only the resulting html code then you have to override the Render(HtmlTextWriter) procedure.

CJ.
0
 
LVL 18

Accepted Solution

by:
tusharashah earned 500 total points
ID: 12347498
B..M is correct... if you are dealing with DataGrid then what you need here is ItemDataBound event. You'll be able to access everything in DataGrid & will be able to modify it before showing them tom your page!

The way you do it is like following:
-------------------------------------------------------------------------------------------------------------------------------------
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
  switch( e.Item.ItemType )
  {
      case ListItemType.Item:
      case ListItemType.AlternatingItem:
         ( (HyperLink) e.Item.Cells[8].Control[0] ).ImageUrl = "Images\Error.gif";   // Replace 8 with the number of your Image Column
// If you are dealing with Template Column then you need something like following
//                ( (Sytem.Web.UI.WebControls.Image) e.Item.FindControl("Image1") ).ImageUrl = "Images\Error.gif";
  }
}
-------------------------------------------------------------------------------------------------------------------------------------

-tushar
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12347743
Dim wc As New System.Net.WebClient()
Dim html As String = Encoding.ASCII.GetString(wc.DownloadData("http://abstractvb.com"))

Aeros
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12355447
>>(I do not want to handle this with Javascript!)
any specific reason y u do not want to use it .. u case is best suited for that .. just add an id to u iamge tag and change its src value
<img id=myimage src='Images\CheckMark.gif' border='0px'>

then using javscript ....
document.getelementsbyid("myimage").src = 'Images\Error.gif' ;

if not then as mentioned by some others .. itemdatabound is the event that u should look for ..

also when is it that u want to change the image .. when an error occurs during loading the datagrid??
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12703065
Please do have a look at my comments ...
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12746928
i think my answer is more appririate  and easier to execute ... u no split of points for me?
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12746929
i meant "y no split of points for me?"
0
 
LVL 6

Author Comment

by:RaisinJ
ID: 12765229
TheLearnedOne, I forgot to split the points, could you please split these?

Thanks,

RaisinJ
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question