您可以使用jQuery來顯示和隱藏面板(這只是<div>'s
在HTML)。它具有滑動的可能性並保存到服務器的往返行程。
<asp:Panel ID="Panel1" runat="server" style="display: none;">
content
</asp:Panel>
<input type="button" value="Slide Panel" onclick="slidePanel('<%= Panel1.ClientID %>')" />
<script type="text/javascript">
function slidePanel(div) {
if ($('#' + div).css('display') == 'none') {
$('#' + div).slideDown('medium', function() { });
} else {
$('#' + div).slideUp('medium', function() { });
}
}
</script>
不過,如果你需要做的,因爲在Panel1
內容的回傳,你可以做的時候調用slidePanel
功能。
protected void Button1_Click(object sender, EventArgs e)
{
Panel1.Visible = true;
//set the dom visibility to none
Panel1.Attributes.Add("style", "display:none");
//call the function to slide the panel open
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "slidePanel", "slidePanel('" + Panel1.ClientID + "')", true);
//or with a 1 second delay (1000 ms)
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "slidePanel", "setTimeout(function() { slidePanel('" + Panel1.ClientID + "'); }, 1000);", true);
}
首先感謝這個的,這是工作的罰款對我,但我也想瓦解它回來時,我點擊關閉按鈕,我如何做到這一點? –
通過做完全相同的事情。 'slidePanel'函數檢查div是否打開或關閉,並通過再次滑動來反轉它。如果你想在PostBack上做,你必須將'Panel1.Attributes'改爲'display:block' – VDWWD