C# .NET 4.0 Get the Value of an ID of a web element by reading the .aspx page with filestream or streamreader

StackOverflow https://stackoverflow.com/questions/7394460

Question

So here's the problem I am writing a program that is going to look through the folder on the localhost before it is rendered. I want to be able to get the value of the ID of a web element and store that in a list object.

For example I have a page:

<html>
<body>

<CustomControl:MyPhoneValidationControl ID="PhoneValidator" validationgroup="PageValidation" />

<CustomControl:MyEmailValidationControl ID="EmailValidator" validationgroup="PageValidation" />

</body>
</html>

The program will go to C:\WebFolder\Page.aspx and then will read the file and find every CustomControl on the page and then grab the Control Type (MyPhoneValidationControl OR MyEmailValidationControl) and then assign the value of the ID (PhoneValidator, EmailValidator) as a property of the Control object.

I am using C#.NET 4.0. Getting the ID of the element is easy after the page is rendered but it doesn't show that it is a custom control. To see the custom control you need to look at the .aspx file without it being rendered by a web server (IIS, etc.)

Was it helpful?

Solution

I resolved myself this by stuffing the page data into a string and then using

string page = new StreamReader(page).ReadToEnd();
List<string> control = new List(string)();
MatchCollection matchControl = Regex.Matches(text, "expression");
foreach (Match match in matchControl)
{
  control.Add(match.Value)
}

This catches the control to a list and then I can parse the string list to get the type and ID using Regex in the properties after passing the whole control List to the controls constructor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top