Results 1 to 12 of 12

Thread: How get between html tag values in codebehind in asp.net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up 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

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: How get between html tag values in codebehind in asp.net

    did you tried :

    Code:
    div1.Value
    ?
    * 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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up 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

  4. #4
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    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

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    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 .

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    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

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    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

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: How get between html tag values in codebehind in asp.net


  9. #9
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    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

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Re: How get between html tag values in codebehind in asp.net

    Hi Motil,

    For your reference,

    <DIV class="end_point point_a">Clark &amp; 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

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    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

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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
  •  



Click Here to Expand Forum to Full Width