Assuming I have the following ASP.NET HTML Code:
<html>
<head><title>Test Page</title></head>
<body id="bodyID">
<asp:Label runat="server" id="lbl1" text="First Name:" />
<asp:TextBox runat="server" id="txt1" /><br />
<asp:Label runat="server" id="lbl2" text="Last Name:" />
<asp:TextBox runat="server" id="txt2"></asp:TextBox>
</body>
</html>
I am trying to write a linq query that will retrieve all the ID’s from any asp tag. Also, the query needs to group everything together alphabetically. So for the example above, the linq query should return “lbl1”, followed by “lbl2”, followed by “txt1”, and finally “txt2”. Notice it did not grab the “bodyID” because it was not part of an ASP.NET tag. Is there an easy way to do this? I am using C#, by the way.
If you’d like to use Linq To XML, you’d have to work around the
<asp:>tags and that they don’t load cleanly into XML.This code will get you what you’re looking for, assuming:
The replacement of the
asp:withasp-may cause trouble if you have any validasp:content that isn’t in a tag. This could be cleaned up to make it suit your needs.