[SOLVED] $(selector).text() equivalent in c# (Revised)

Issue

I am trying check if the inner html of the element is empty but I wanted to do the validation on the server side, I’m treating the html as a string. Here is my code

public string HasContent(string htmlString){
    // this is the expected value of the htmlString

    //  <span class="spanArea">
    //      <STYLE>.ExternalClass234B6D3CB6ED46EEB13945B1427AA47{;}</STYLE>
    //  </span>

    // From this jquery code-------------->
    // if($('.spanArea').text().length>0){
    //  
    // }
    // <------------------
    // I wanted to convert the jquery statement above into c# code. 

    /// c# code goes here
    return htmlSTring;
}

using this line

$('.spanArea').text() // what is the equivalent of this line in c#

I will know if the .spanArea does really have something to display in the ui or not. I wanted to do the checking on the server side. No need to worry about how to I managed to access the DOM I have already taken cared of it. Consider the htmlString as the Html string.

My question is if there is any equivalent for this jquery line in C#?

Thanks in advance! 🙂

Solution

If you really need to get that data from the HTML in the ServerSide then I would recommend you to use a Html-Parser for that job.

If you check other SO posts you will find that Html Agility Pack was recommended many times.

Answered By – Mariano Desanze

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *