• 关于模式窗体关闭后刷新主页面的问题


    1.有些时候用到模式弹出窗体,传递参数。根据应用不同,有的需要在弹出框关闭时刷新父页面, 有的不允许刷新父页面。 

    在这里实现的方式,主要是判断模式窗体返回值,可以直接把值填充到父页面控件中(不刷新),也可以让页面刷新取子页面里的Session值 

    下面用一个例子说明,有两个页面Default.aspx 和 InputMessage.aspx ,贴代码:

    Default.aspx

    View Code

    Default.aspx.cs

    View Code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = "未登录";
            if (Session["userid"] != null && Session["username"] != null)
            {
                Label1.Text ="<font color='red'>用户编号:"+ Session["userid"].ToString().Trim() + "    用户名:" + Session["username"].ToString()+"</font>";
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "msg", "var r=window.showModalDialog('inputMessage.aspx',{'name':'张三丰','age':88},'dialogWidth=16; dialogHeight=9;scroll=no; status=no;center=yes'); if (r == undefined) window.location=location;", true);
    
        }
    }

    InputMessage.aspx

    View Code
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="inputMessage.aspx.cs" Inherits="InputMessage" %>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>个人信息输入</title>
        <style type="text/css">
            #Button1
            {
                height: 41px;
                 137px;
            }
        </style>
    </head>
    <base target="_self" />
    <body>
        <form id="form1" runat="server">
        <div>
            <table style="100%;" cellpadding="20">
                <tr>
                    <td align="center">
            姓名:<input id="Text1" type="text" /><br />
            年龄:<input id="Text2" type="text" /><br />
            <input id="Button1" type="button" value="登录后不刷新" onclick="return GO()" />
            <script type="text/javascript">
                var args=window.dialogArguments;
                document.getElementById('Text1').value=args.name;
                document.getElementById('Text2').value=args.age;
                function GO() {
                    window.returnValue = { "user": document.getElementById('Text1').value, "age": document.getElementById('Text2').value };
                    window.close();
                }
    </script>
                   <asp:Button ID="Button2" runat="server" Text="登录后刷新" onclick="Button2_Click"  Height="41px" Width="145px" />
                    </td>
                </tr>
            </table>
        </div>
        </form>
    </body>
    </html>

    InputMessage.aspx.cs

    View Code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class InputMessage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            string userID = "";
            string userName = "";
            //验证登录
            //登录失败-- 继续 
            //登录成功-- 保存Session,更新主页面显示用户信息
            Session.Add("userid", "111");
            Session.Add("username", "小王");
            Response.Write("<script language='javascript'>");
            Response.Write("window.close()");
            Response.Write("</script>"); 
        }
    }
  • 相关阅读:
    Educational Codeforces Round 67 D. Subarray Sorting
    2019 Multi-University Training Contest 5
    Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code
    Educational Codeforces Round 69 D. Yet Another Subarray Problem
    2019牛客暑期多校训练第六场
    Educational Codeforces Round 68 E. Count The Rectangles
    2019牛客多校第五场题解
    2019 Multi-University Training Contest 3
    2019 Multi-University Training Contest 2
    [模板] 三维偏序
  • 原文地址:https://www.cnblogs.com/kingkongv/p/2761754.html
Copyright © 2020-2023  润新知