I wish I could go all the elements of an ASP.Net page (HTML elements) and manipulate its text property / value. How could I do that?
I’ve been checking, and the property this.Page.Form.Controls apparently gets all the elements, but I would only page elements that caught the event. Does anyone have any idea.
I’ll put an example of code that I’m currently studying and trying adpater for my needs.
Thanks
string x = String.Empty;
string y = String.Empty;
foreach (Control ctrl in this.Page.Form.Controls){
if (ctrl is TextBox){
x += ((TextBox)(ctrl)).ID + ((TextBox)(ctrl)).Parent + "\n";
} else {
y += ctrl.GetType().Name + ctrl.GetType().Namespace + "\n";
}
}
Obs.: I am using some components of the Telerik components.
The controls on a page are stored in a tree data structure. You could use a recursive method to do this:
and you would call this method somewhere like let’s say, in the OnPreRender Event (to make sure that you get all controls that have been added to the page) and pass the Page.Controls ControlCollection: