我已经在我的网站下面的code:
I have the following code on my website:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="myButton_btn" eventname="Click" />
</Triggers>
<ContentTemplate>
<script>
function pageLoad(){
window.alert("<%=Session("myVariable")%>");
}
}
</script>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="myButton_btn" Text="Prev Month" runat="server"></asp:Button>
JavaScript的运行每次我点击按钮。不过,即使我的子程序点击按钮后更新会话变量,我总是得到同样的警告。换言之,相同的JavaScript是回发后运行,并且它不被更新。我肯定的会话变量正在改变。有谁知道为什么发生这种情况?我AP preciate您的输入!
The javascript is running everytime I click the button. However, even though my subroutine updates the session variable after clicking the button, I always get the same alert. In other words, the same javascript is run after postback, and it is not updated. I am positive that the session variable IS being changed. Does anyone know why this is happening? I appreciate your input!
感谢你了!
在按钮处理程序试试这个:
Try this in the button-handler:
VB.Net
ScriptManager.RegisterStartupScript(Me.UpdatePanel, GetType(string), "alertScript", String.Format("alert('{0}');",Session("myVariable")), true)
C#
ScriptManager.RegisterStartupScript(this.UpdatePanel, typeof(string), "alertScript", string.Format("alert('{0}');", Session["myVariable"]), true);