zoukankan      html  css  js  c++  java
  • 关于模式窗体关闭后刷新主页面的问题

    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>"); 
        }
    }
  • 相关阅读:
    MindSpore 建立神经网络
    MindSpore 数据加载及处理
    MindSpore 初探, 使用LeNet训练minist数据集
    Ubuntu 20.04 Xrdp Black Screen Ubuntu 20.04 Xrdp 远程桌面黑屏
    基于Transformer的ViT、DETR、Deformable DETR原理详解
    Ubuntu 18.04 / 20.04 自定义锁屏时间
    Transformer中K 、Q、V的设置以及为什么不能使用同一个值
    Auto-Encoding Scene Graphs for Image Captioning
    Eureka中读写锁的奇思妙想,学废了吗?
    PostgreSQL-查询所有索引
  • 原文地址:https://www.cnblogs.com/kingkongv/p/2761754.html
Copyright © 2011-2022 走看看