当前位置:编程学习 > C#/ASP.NET >>

C#后台弹出式窗口,如何不让他自动刷新页面呢?

状况:页面通过 GridView显示出 客户的明细信息,点击选择一行数据,根据选择行的ID弹出显示详细信息;弹出窗口效果通过下面的实现的,但是有一个问题是,窗口弹出后,父窗口自动刷新了,如何让父窗口的内容不动呢?
------------------------------------------------------------------------------------------
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strCust_ID;
            strCust_ID = GridView1.SelectedRow.Cells[2].Text.Trim();//ID
            string scriptstr;
            scriptstr = "<script language=javascript>showModalDialog('cust_one.aspx?ID=" + strCust_ID + "','客商信息维护','dialogWidth:800px;dialogHeight:600px;center:true;help:no;resizeable:yes;status:yes')</script>";
            Response.Write(scriptstr);
        } --------------------编程问答-------------------- 使用js在前端做, --------------------编程问答-------------------- 用js前台弹出,搜索js 弹窗 --------------------编程问答--------------------
找一个jquery的组件,在后台封装一下。
然后照样在cs代码中调用,前台也不会刷新。
http://www.open-lib.com/Type/175-1.jsp --------------------编程问答-------------------- 用js调用吧,后台触发的一般都会刷新页面的 --------------------编程问答-------------------- --------------------编程问答--------------------
引用 楼主 rencaitian 的回复:
状况:页面通过 GridView显示出 客户的明细信息,点击选择一行数据,根据选择行的ID弹出显示详细信息;弹出窗口效果通过下面的实现的,但是有一个问题是,窗口弹出后,父窗口自动刷新了,如何让父窗口的内容不动呢?
------------------------------------------------------------------------------------------
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strCust_ID;
            strCust_ID = GridView1.SelectedRow.Cells[2].Text.Trim();//ID
            string scriptstr;
            scriptstr = "<script language=javascript>showModalDialog('cust_one.aspx?ID=" + strCust_ID + "','客商信息维护','dialogWidth:800px;dialogHeight:600px;center:true;help:no;resizeable:yes;status:yes')</script>";
            Response.Write(scriptstr);
        }


如果就是需要在后台弹出,用下面这种方式吧:
ScriptManager.RegisterStartupScript(this, this.GetType(), "EditSuccess", "alert('" + message + "');", true);

第三个参数是key,不填也行
第四个参数是你的javascript
第五个参数是addScriptTags,我一般默认是true,不太清楚啥意思。

注意点: 你页面上要有
 <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

你可以试试.
--------------------编程问答-------------------- 不要用Response.Write();
你可以定义一个控件,在后台用这个控件的点击方法打开,这样就不会有回传了
HyperLink hl_1 = (HyperLink)e.Item.FindControl("hl_1");
hl_1.Attributes.Add("onclick", "window.showModalDialog('cust_one.aspx?ID=" + strCust_ID + "','客商信息维护','dialogWidth:800px;dialogHeight:600px;center:true;help:no;resizeable:yes;status:yes'"); --------------------编程问答--------------------
引用 6 楼 bubu05690523 的回复:
Quote: 引用 楼主 rencaitian 的回复:

状况:页面通过 GridView显示出 客户的明细信息,点击选择一行数据,根据选择行的ID弹出显示详细信息;弹出窗口效果通过下面的实现的,但是有一个问题是,窗口弹出后,父窗口自动刷新了,如何让父窗口的内容不动呢?
------------------------------------------------------------------------------------------
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strCust_ID;
            strCust_ID = GridView1.SelectedRow.Cells[2].Text.Trim();//ID
            string scriptstr;
            scriptstr = "<script language=javascript>showModalDialog('cust_one.aspx?ID=" + strCust_ID + "','客商信息维护','dialogWidth:800px;dialogHeight:600px;center:true;help:no;resizeable:yes;status:yes')</script>";
            Response.Write(scriptstr);
        }


如果就是需要在后台弹出,用下面这种方式吧:
ScriptManager.RegisterStartupScript(this, this.GetType(), "EditSuccess", "alert('" + message + "');", true);

第三个参数是key,不填也行
第四个参数是你的javascript
第五个参数是addScriptTags,我一般默认是true,不太清楚啥意思。

注意点: 你页面上要有
 <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

你可以试试.


用下面这种也是可以的:
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('Please Choose Region.')</script>");
--------------------编程问答--------------------
引用 6 楼 bubu05690523 的回复:
如果就是需要在后台弹出,用下面这种方式吧:
ScriptManager.RegisterStartupScript(this, this.GetType(), "EditSuccess", "alert('" + message + "');", true);

第三个参数是key,不填也行
第四个参数是你的javascript
第五个参数是addScriptTags,我一般默认是true,不太清楚啥意思。

注意点: 你页面上要有
 <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

你可以试试.

楼上的方法也很好用,我平时就是这样用的 --------------------编程问答-------------------- 那就不能在GridView1_SelectedIndexChanged事件中去处理

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if(e.Row.RowIndex>=0)
            {
                string strCust_ID = e.Row.Cells[2].Text.Trim();//ID

                e.Row.Attributes.Add("onclick","showModalDialog('cust_one.aspx?ID=" + strCust_ID + "','客商信息维护','dialogWidth:800px;dialogHeight:600px;center:true;help:no;resizeable:yes;status:yes')");
            }
        } --------------------编程问答-------------------- 我觉得这个东西多有用的,但用的人很少,不知道为什么

客户端回调 --------------------编程问答-------------------- 不能在後端代碼寫,後端都會刷新頁面,用js --------------------编程问答-------------------- 不想刷新  只能用 js了
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,