1

I have a large string containing a custom HTML tag (xxx). The tag also has two attributes.

How would I retrieve the value of the two attributes and then place the tag and its content with a new string derived from those two attributes?

Thanks for your time.

2 Answers 2

3

Where do you want to retrieve it? In the code behind?

If your tag is runat="server", you can do:

mytag.Attributes["nameofmyattribute"]
Sign up to request clarification or add additional context in comments.

5 Comments

It will be retrieved from the code behind but the tag isn't part of the page it is inside a string containing other HTML elements. I just need to find my custom tag and get the attributes from it.
So you have a string in the code behind containing a long HTML code, and you need to find your tag in that string?
That is correct yes, then retrieve the attribute values from that tag.
I don't get your problem... If is that just look for the substring of your tag... Sample: If you want some <span> tag , search for the occurrences of substring <span ....
webforms almost died. What will be the similar case if it is not webform code behind and it is a asp.net mvc controller code?
1

If its in string then you should consider using HTML Agility Pack. However it may be overkill so show us some sample string... maybe only some RegEx can do it.

1 Comment

Ok, well the string will contain roughly a paragraph of text, with an indefinite number (generally 1-12) of tags in the following format: <template category="x" field="y">text</template>. I will then pass x and y to a function which will return a string to replace the text inside the template tag (including the template tag) with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.