您可以使用OnClientClick
。例如:
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="MyFunction();" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>
它會在OnClick事件之前觸發。
你的JavaScript函數:
<script type="text/javascript">
function MyFunction() {
document.getElementById('sched').style.display = 'block';
}
</script>
添加UpdatePanel
爲AsyncPostBack
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="MyFunction();" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div id="sched">
// Your code
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
ASP.NET Web窗體。 – jelliaes