各位好:遇到一个棘手的问题,在打开的模式窗体中,点击服务器按钮控件,在按钮事件中写
ClientScript.RegisterStartupScript(this.GetType(), "submitOk", "alert('123');",true);弹出两次提示窗体!不明白为何弹出两次,具体代码如下。页面1:调用模式窗体的父窗体
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="htManage_TestPage" %><head runat="server">
    <title>1</title>
    <script language="javascript">
     function showErrMsg()
        {
              window.showModalDialog("TestPageFrame.aspx","","center=yes;dialogHeight=20;dialogWidth=20;resizable=yes;status=yes;scroll=yes;help=no");
        }
      </script>
</head>
<body>
    <form id="form1" method="post" runat="server">
    <div>
        <input onclick="return showErrMsg();" type="button" value="保 存" id="button2" name="btnSave" />
    </form>
</body>
</html>页面2:模式窗体的加载窗体<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPageFrame.aspx.cs" Inherits="htManage_TestPageFrame" %><head >
    <title>2</title>
        <base target="_self"></base>
</head>    <frameset rows="0,*">
    <frame src="about:blank">
    <frame src="TestPage2.aspx">
      </frameset>
</html>页面3: 模式窗体<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Testpage2.aspx.cs" Inherits="htManage_Testpage2" %><head>
    <title>3</title>
    <base target="_self"></base>
     <script language="javascript">
    function showErrMsg()
        {
              window.showModalDialog("TestPage3.aspx","","center=yes;dialogHeight=20;dialogWidth=20;resizable=yes;status=yes;scroll=yes;help=no");
}
        </script>
</head>
<body>
    <form id="form1" runat="server" method="post">
    <div>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        <input type="button" value="关闭" onclick="window.close()">
    </div>
    </form>
</body>
</html>
页面4:模式窗体的后台代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class htManage_Testpage2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "submitOk", "alert('123');",true);
    }
}在这里先谢过各位达人,不吝赐教。

解决方案 »

  1.   

    ClientScript.RegisterStartupScript(this.GetType(), "submitOk", "alert('123');",true);
    这句改成
    ClientScript.RegisterStartupScript(this.GetType(), "submitOk", "123",true);试下
      

  2.   

    ClientScript.RegisterStartupScript(this.GetType(), "submitOk", "alert('123');",true);
    这句改成
    ClientScript.RegisterStartupScript(this.GetType(), "confirm", "123",true);试下
      

  3.   

    http://www.cshap.cn/
    或许能找到你感兴趣的问题
      

  4.   

    更正:
    ClientScript.RegisterStartupScript(this.GetType(),"alert","<script>alert('123')</script>",true)
      

  5.   

    我上面回答不对,
    刚才你你代码试下,就出来一次呀,html哪里出错
      

  6.   


    更正:
    ClientScript.RegisterStartupScript(this.GetType(),"alert","<script>alert('123')</script>",true)
    ============================================
    0次
    睡觉
      

  7.   

    4。防止打开新窗口(如提交表单):
    <base target="_self">
      

  8.   

    是否应该用IsStartupScriptRegistered来避免重复注册脚本.
      

  9.   

    ClientScript.RegisterStartupScript(this.GetType(), "submitOk", "alert('123');",true);
    ===============================================
    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('123')</script>");
      

  10.   

    你的起始页究竟是哪个..我测试没有问题注意一下换行 window.showModalDialog("TestPageFrame.aspx","","center=yes;dialogHeight=20;dialogWidth=20;resizable=yes;status=yes;scroll=yes;help=no");
    ============================= window.showModalDialog("TestPage3.aspx","","center=yes;dialogHeight=20;dialogWidth=20;resizable=yes;status=yes;scroll=yes;help=no");
      

  11.   

    window.showModalDialog("TestPageFrame.aspx","","center=yes;dialogHeight=20;dialogWidth=20;resizable=yes;status=yes;scroll=yes;help=no");
      

  12.   

    起始页为TestPage.aspx;然后通过按钮打开模式窗体TestPage2.aspx,它是嵌在框架页面TestPageFrame.aspx页面里的,怎么看到很多达人说测试只弹出一次?晕啊。请各位再发表一下观点,不胜感激
      

  13.   

    很感谢各位参与,特别谢谢空空儿,他的意见让我最终找到错误,根源在于我的web.config配置文件中 <system.web>块<page  smartNavigation="true"/>子块中添加了智能导航属性,虽然深层次的问题原因未弄清楚,应该是同页面的JavaScript脚本有所冲突,不过总算解决了。谢谢各位