Option 1: If you can make the decision as the page is rendered, i.e. server-side:
In your code-behind:
protected void Page_Load()
{
if (variableToSwitchOn == true)
{
button1.Visible = true;
button2.Visible = false;
}
else
{
button1.Visible = false;
button2.Visible = true;
}
}
In your .aspx page:
<div>
<asp:button runat="server" ID="button1" Text="Button 1" />
<asp:button runat="server" ID="button2" Text="Button 2" />
</div>
Option 2: If you need to make the decision client-side
In your .aspx page:
<div>
<asp:button runat="server" ID="button1" Text="Button 1" />
<asp:button runat="server" ID="button2" Text="Button 2" />
</div>
<script language="javascript" type="text/javascript">
var button1Id = '<%=button1.ClientId%>';
var button2Id = '<%=button2.ClientId%>';
</script>
You can now have a piece of javascript that controls whether the buttons are visible, for example:
function ChangeWhichButtonIsVisible()
{
var button1 = document.getElementById(button1Id);
var button2 = document.getElementById(button2Id);
if (someCondition == true)
{
button1.style.display = 'none';
button2.style.display = 'block';
}
else
{
button1.style.display = 'block';
button2.style.display = 'none';
}
}