我在的.aspx页面(HTML标记)有一个脚本工作:脚本代码不与方法
<div id="alert">
<asp:Label ID="lblAlert" style="font-size: xx-large" runat="server"></asp:Label>
</div>
<!-- /.alert -->
<script>
function AutoHideAlert(v) {
var al = document.getElementById('<%=lblAlert.ClientID%>');
al.innerText = v;
$("#alert").fadeTo(3500, 500).slideUp(1500, function() {
$("#alert").slideUp(500);
});
}
</script>
我打电话aspx.cs文件AutoHideAlert(v)
功能(代码-Behind)使用RegisterStartupScript
和我在ShowMessage
方法添加RegisterStartupScript
:
private void ShowMessage(string msg)
{
ScriptManager.RegisterStartupScript(this, GetType(), null, "AutoHideAlert('"+msg+"');", true);
}
问题是,当我打电话ShowMessage
我包含脚本代码行的thod不工作。但是当我运行脚本代码行然后它的工作;问题是为什么它不与ShowMessage
一起运行?
编辑1:从@ M4N的评论,我试图通过设置第三个参数"Alert Message"
但它仍然无法正常工作。
private void ShowMessage(string msg)
{
ScriptManager.RegisterStartupScript(this, GetType(), "Alert Message", "AutoHideAlert('"+msg+"');", true);
}
你试过将'key'参数(第三个参数)设置为某个值? – M4N