How get between html tag values in codebehind in asp.net
Hi,
I need a suggestion for below code
<HTML>
<Head>
</Head>
<Body>
<div id="div1" runat="server"> My Name is Guvera </div>
</Body>
</HTML>
In the above HTML i need to take a string "My Name is Guvera" using Asp.Net code.
Is it possible? If possible, kindly help me.
Hope your's reply.
Regards
Guvera
Re: How get between html tag values in codebehind in asp.net
Re: How get between html tag values in codebehind in asp.net
Hi,
Thanks for your reply.
div are generated dynamically. I gave sample example in my previous post here.I am using google map javascript API to get the direction between start and end point. Each driving direction is embedded within a div. I want to get the direction text . It can be multiple direction text. The code is from client side. I cant publish here. So i explained my actual scenario above.
So please give some other suggession.
Regards
Guvera
Re: How get between html tag values in codebehind in asp.net
I'm sorry I don't exactly understand what you really want do, those div's are generated by google maps API? and on postback you want to get their inner text ?
Re: How get between html tag values in codebehind in asp.net
First , you need runat=server tag appended to html control to be able to get it's value .
as for your scenario , you need to get any html parser to get text out of divs , i'd suggest . I can't remember exactly the name of the parser but i can look for it if you need .
Re: How get between html tag values in codebehind in asp.net
Hi,
Dynamically generated HTML will never get posted back to the server unless you either copy it to a hidden field prior to postback, or make an ajax call and manually pass the dynamic HTML to it. So I have copied that code to hidden field prior to postback. Before postback i had set the innerHTML of the div to the hidden field.I need to get only the text from the HTML content. This need to work in all browsers. This is my scenario. Hope you get my point.
Regards
Guvera
Re: How get between html tag values in codebehind in asp.net
Hi Pirate,
Thanks for your reply. May i know the name of HTMLParser. Could you please suggest me?
Regards
Guvera
Re: How get between html tag values in codebehind in asp.net
Re: How get between html tag values in codebehind in asp.net
do you have any container that holds all the divs that generated by google's API?
Re: How get between html tag values in codebehind in asp.net
Hi Motil,
For your reference,
<DIV class="end_point point_a">Clark & Pratt </DIV>
<DIV class=point>
<DIV class=point_number>1</DIV>
<DIV class=point_distance>0.5 mi</DIV>
<DIV class=point_description>Head <STRONG>north</STRONG> on <STRONG>N Clark St</STRONG> toward <STRONG>W Farwell Ave</STRONG> </DIV></DIV>
<DIV class=point>
<DIV class=point_number>2</DIV>
<DIV class=point_distance>0.4 mi</DIV>
<DIV class=point_description>Turn <STRONG>left</STRONG> on <STRONG>W Toughy Ave</STRONG> </DIV></DIV>
<DIV class=point>
Regards
Guvera
Re: How get between html tag values in codebehind in asp.net
Hi,
I saw one forum that Regular expressions will help you to strip the html from the text. You may find it easier to post the text (including html) to the server and parse is server-side using the Regex object, that way yuo don't have to worry about specific browsers support for regex. I tried like
Dim RegExp As System.Text.RegularExpressions.Regex = New Regex("\\<[^\\>]*\\>")
DrivingDirections = Regex.Replace(DrivingDirections, "\\<[^\\>]*\\>", "")
But i got the same output. what is the problem?
Regards
Guvera
Re: How get between html tag values in codebehind in asp.net
Hello,
The HtmlAgilityPack that has already been suggested will do the work of the above Regular Expression. Personally, I would choose to use that, rather than trying to hand crank some Regex.
Gary