使用ScriptManager时出错.RegisterStartupScript

Error using ScriptManager.RegisterStartupScript

本文关键字:RegisterStartupScript 出错 ScriptManager 使用      更新时间:2023-09-26

从服务器端,我使用按钮点击事件中的闲置代码调用一个aa()javascript函数:

受保护的子按钮1_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理按钮1.ClickDim bbb As String="aa();"ScriptManager。RegisterStartupScript(Me,GetType(Page),"123",bbb,False)结束子

客户端代码是这样的:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" /></div>
    </form>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type ="text/javascript">
    function aaa() 
    {
        alert("hola");
    }

</script>
</body>
</html>

当我点击按钮时,我收到错误消息"aaa"未定义我做错了什么?

您的<script>应该在<head>部分内,或者至少在调用aaa()的部分之前。

现在,您正在定义aaa(),因为它已经初始化了您的按钮。