Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Javascript弹出窗口_Asp.net - Fatal编程技术网

Asp.net Javascript弹出窗口

Asp.net Javascript弹出窗口,asp.net,Asp.net,我试图从代码隐藏打开此模式DIV,但收到错误消息。请告诉我这有什么问题 这是.aspx代码 <div id="modal" runat="server" style="display:none;"> <asp:Button ID="btnClose" runat="server" Text="Close" onClick="Popup.hide('modal')" CausesValidation="False"/> </div> 对于您提到的错误

我试图从代码隐藏打开此模式DIV,但收到错误消息。请告诉我这有什么问题

这是.aspx代码

<div id="modal" runat="server" style="display:none;">
    <asp:Button ID="btnClose" runat="server" Text="Close" onClick="Popup.hide('modal')" CausesValidation="False"/>
</div>

对于您提到的错误

"Too many characters in character literal when loading the page"
您必须使用OnClientClick而不是onClick,因为它是ASP.NET服务器控件,而不是普通的HTML5控件

对于您要求的代码: 页面加载时打开模式的代码 ASPX代码

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>
            function hidePopup()
            {
                document.getElementById('modal').close();
            }
        </script>
</head>
<body  onload="showPopup();">
    <form id="form1" runat="server" >
  <dialog id="modal">
    <asp:Button ID="btnClose" runat="server" Text="Close" OnClientClick="hidePopup();return false;"/>
</dialog>
    </form>
</body>
</html>
在Chrome版本39.0.2171.99 m上进行测试,效果完美


使用此模式,您也可以使用“Esc”键退出弹出窗口,而不是关闭按钮。

您是否可以发布实际错误消息?仅仅说你有一个是没有多大帮助的“加载页面时,字符文字中的字符太多。这可能是弹出脚本本身的问题;FireFox+FireBug可能能够快速充实错误源。这是JavaScript中的错误,还是代码中的错误?C#在单引号内看到字符串时经常抛出该错误(如“model”)
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>
            function hidePopup()
            {
                document.getElementById('modal').close();
            }
        </script>
</head>
<body  onload="showPopup();">
    <form id="form1" runat="server" >
  <dialog id="modal">
    <asp:Button ID="btnClose" runat="server" Text="Close" OnClientClick="hidePopup();return false;"/>
</dialog>
    </form>
</body>
</html>
if (!Page.ClientScript.IsStartupScriptRegistered("MyScript"))
                {
                    string confirmbox = "function showPopup(){document.getElementById('modal').showModal();}";
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", confirmbox, true);
                }