|
-
Feb 9th, 2011, 03:57 AM
#1
Thread Starter
Addicted Member
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
Failing to plan is Planning to fail 
-
Feb 9th, 2011, 04:22 AM
#2
Re: How get between html tag values in codebehind in asp.net
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Feb 9th, 2011, 04:30 AM
#3
Thread Starter
Addicted Member
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
Failing to plan is Planning to fail 
-
Feb 9th, 2011, 04:41 AM
#4
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 ?
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Feb 9th, 2011, 04:44 AM
#5
Sleep mode
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 .
-
Feb 9th, 2011, 04:51 AM
#6
Thread Starter
Addicted Member
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
Failing to plan is Planning to fail 
-
Feb 9th, 2011, 04:53 AM
#7
Thread Starter
Addicted Member
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
Failing to plan is Planning to fail 
-
Feb 9th, 2011, 04:58 AM
#8
Sleep mode
Re: How get between html tag values in codebehind in asp.net
-
Feb 9th, 2011, 05:00 AM
#9
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?
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Feb 9th, 2011, 05:05 AM
#10
Thread Starter
Addicted Member
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
Failing to plan is Planning to fail 
-
Feb 9th, 2011, 05:06 AM
#11
Thread Starter
Addicted Member
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
Failing to plan is Planning to fail 
-
Feb 9th, 2011, 07:56 AM
#12
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|