Monday, October 11, 2004

Getting a Control's Property using Reflection

******this code block loops thro the controls and gets the associated text entered in the TextBox using Reflection******

foreach(Control c in this.Controls)
{
if(c.ToString() == "System.Web.UI.TextBox")
{
PropertyInfo p1 = c.GetType().GetProperty("Text");
string strVal = p1.GetValue (c,BindingFlags.GetProperty,null,null,null).ToString();
}
}

No comments: