On my aspx page has a button. I want to change its property dynamically.
For example:
A button which ID is Button1 and I want to change its property Visible to false.
On code behind have three variables hidefield = "Button1"
, property = "Visible"
and value = false
.
Is it possible to set the property Visible using the variables?
aspx:
<asp:Button ID="Button1" runat="server" Text="Button1" />
code behind:
protected void Page_Load(object sender, EventArgs e)
{
string hidefield = "Button1";
string property = "Visible";
bool value = false;
if (!IsPostBack)
{
Control myControl1 = FindControl(hidefield);
if (myControl1 != null)
{
myControl1.property = value; // <- I know this statement has error. Is there any way to set the property like this?
}
}
}