選項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