2010-11-04 43 views
1

我想从后面的代码中打开这个模态DIV,但是我收到错误消息。请让我知道这有什么问题。Javascript popup

这里是.aspx代码。

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

代码背后

 if (!Page.ClientScript.IsStartupScriptRegistered("MyScript")) 
     { 
      string confirmbox = "Popup.showModal('modal');return false;"; 
      Page.ClientScript.RegisterClientScriptBlock(GetType(), "MyScript", confirmbox, true); 
     } 
+0

请问您可以发布实际的错误消息说什么?只是说你有一个不是很有帮助。 – Brandon 2010-11-04 16:27:36

+0

我收到了“加载页面时字符文字太多的字符 – nav100 2010-11-04 16:28:00

+0

这可能是Popup脚本本身的问题; FireFox + FireBug可能能够快速填充该错误源 – 2010-11-04 16:44:16

回答

0

对于你所提到的错误作为

"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> 

码.CS码

if (!Page.ClientScript.IsStartupScriptRegistered("MyScript")) 
       { 
        string confirmbox = "function showPopup(){document.getElementById('modal').showModal();}"; 
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", confirmbox, true); 
       } 

测试在Chrome的版本了:39.0.2171.99米,它完美的作品。

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