选项1:如果你能做出决定,因为页面呈现,即服务器端:
在你的后台代码:
protected void Page_Load()
{
if (variableToSwitchOn == true)
{
button1.Visible = true;
button2.Visible = false;
}
else
{
button1.Visible = false;
button2.Visible = true;
}
}
在.aspx页面:
<div>
<asp:button runat="server" ID="button1" Text="Button 1" />
<asp:button runat="server" ID="button2" Text="Button 2" />
</div>
选项2:如果你需要做出决定的客户端
在.aspx页面:
<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>
你现在可以有一段JavaScript控制的按钮是否可见,例如:
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';
}
}
来源
2010-08-11 17:36:20
Rob
你有什么问题,你不觉得这是可能的。只需使用客户端的CSS来隐藏和显示其他。然后你可以切换一些JavaScript,如果你需要它们都来到页面。 – spinon 2010-08-11 17:35:15