首页 > 代码库 > 弹出新界面,在新界面执行方法后传参给调用界面,再执行调用界面的方法

弹出新界面,在新界面执行方法后传参给调用界面,再执行调用界面的方法

需求:收费界面如果按照客户名称来检索,且有重名的话,能弹出多个客户来选择

思路:利用jquery和第三方的js库lhgdialog.min.js(我这里是为了快速、方便、美观、不用考虑兼容性),当点击查询时,调用弹出窗体,弹出窗体引用了一个单独的aspx页面,这个aspx页面将列出查询到的数据列表,然后根据选择不通的数据行,将唯一标识再传给调用页面(主页面),最后执行调用页面(主页面)的方法。

界面效果如下:

技术分享

技术分享

技术分享

aspx页面:

    <script src=http://www.mamicode.com/"JS/jquery-1.10.2.min.js"></script>>这里我使用了第三方js库lhgdialog.min.js,这个大家可以去网上下载。

js代码如下:

<script type="text/javascript">
       //弹出框
        var dg;
        function showPublishWin(accountName) {
            dg = new $.dialog({
                id: "AccountListSelect",
                title: "查询到的客户列表",
                content: "url:AccountListSelect.aspx?AccountName=" + accountName,
                width: 740,
                height: 120,
                max: false,
                min: false,
                lock: true,
                close: true,
                cancel: true, //X按钮是否显示,如果设置了回调函数,一定会显示
                //cancel: controlAllBtn,
                ok: setAccountNumber
            });
            dg.show();
        }
        function setAccountNumber(data) {
            var v = this.content.document.getElementById("hidfSelectAccountNumber").value; //获取弹出窗体界面的值
            $("#txtAccountNo").val(v);
            dg.hide();
            ShowDiv();
            __doPostBack("btnSearch", "");
        }
    function validateInput() {
                var accountName = document.getElementById("txtAccountName").value;
                if (accountName == "" && document.getElementById("txtAccountNo").value =http://www.mamicode.com/= "" && document.getElementById("txtMeterCode").value == "") {>新建一个一般处理程序AccountCountHandler.ashx

    public class AccountCountHandler : IHttpHandler
    {
        private int _maxReturnCount = 10;//每次查询最多返回的欠费记录数
        ComprehensivePayment1 cpp = new ComprehensivePayment1();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string accountName = context.Request["AccountName"];
            int result=GetAccountByAccountName(accountName);
            context.Response.Write(result);
        }

        /// <summary>
        /// 根据客户名称或者客户数
        /// </summary>
        /// <param name="accountName">客户名称</param>
        /// <returns></returns>
        int GetAccountByAccountName(string accountName)
        {
            if (string.IsNullOrEmpty(accountName))
            {
                return 0;
            }
            accountName = HttpUtility.UrlDecode(accountName,System.Text.Encoding.UTF8);
            string fetchXml = @"<fetch version=""1.0"" output-format=""xml-platform"" mapping=""logical"" distinct=""false"">
                                    <entity name=""account"">
                                      <attribute name=""name"" />
                                    <filter type=""and"">
                                     <condition attribute='name' operator='eq' value=http://www.mamicode.com/""" + accountName>新建一个AccountListSelect.aspx页面,用于显示查询到的客户列表信息,这是用于嵌套到模态窗体里面的界面。

aspx代码:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>查询到的客户列表</title>
    <link href=http://www.mamicode.com/"Style/PrepaymentBusiness.css" rel="stylesheet" />>cs代码:

    public partial class AccountListSelect : System.Web.UI.Page
    {
        private int _maxReturnCount = 10;//每次查询最多返回的欠费记录数
        ComprehensivePayment1 cpp = new ComprehensivePayment1();

        protected void Page_Load(object sender, EventArgs e)
        {
            string accountName = Request.QueryString["AccountName"];
            accountName = HttpUtility.UrlDecode(accountName);
            rptAccountList.DataSource = SearchInfoListByAccountName(accountName);
            rptAccountList.DataBind();
        }

        /// <summary>
        /// 根据客户名称查询客户信息列表
        /// </summary>
        /// <param name="accountName">客户名称</param>
        /// <returns></returns>
        DataTable SearchInfoListByAccountName(string accountName)
        {
            if (string.IsNullOrEmpty(accountName))
            {
                return null;
            }
            DataTable dtblRec = null;

            string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='" +
                 _maxReturnCount.ToString() + @"'>
                <entity name='account'>
                <attribute name='accountid' />
                <attribute name='accountnumber' />
                <attribute name='name' />
                <attribute name='address1_name' />
                <filter type='and'>
                <condition attribute='name' operator='eq' value=http://www.mamicode.com/'">PrepaymentBusiness.css样式代码:

/*********************************************************
 * 公司名称:HuaXu
 * 开发人员:ZouQJ
 * 创建时间:2014/10/13 09:36:48
 * 描述说明:
 * 更改历史:
 * *******************************************************/
/*--------------------按钮--------------------------*/
 .btn {
 float: left;    
 border: 1px solid #00748f;
 height: 32px;
 width: 100px;
 padding: 0;
 cursor: pointer;
 font: bold 15px Arial, Helvetica;
 color: #fafafa;
 text-transform: uppercase;    
 background-color: #3385ff;
 background-image: linear-gradient(top, #31b2c3, #3385ff);
 border-radius: 3px;      
 text-shadow: 0 1px 0 rgba(0, 0 ,0, .3);
 box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 1px 0 #fff;
  margin-left:4px;
}
.btn:hover,.btn:focus,.minBtn:hover,.minBtn:focus
 {  
 background-color: #3333FF;
 background-image: linear-gradient(top, #6699FF,#3333FF);
}
.rptCss{
    border: 1px solid #aec7e5;
    clear: both;
    margin-bottom: 40px;
    overflow-x: hidden;
    overflow-y:auto;
    padding: 10px 20px;
    position: relative;
    background-color:White;
    height:120px;
    margin-right: 4px; top: 0px; left: 0px;
    margin-bottom: -37px;
}

.altCss{
background:#fff;  /*这行将给所有的tr加上背景色*/
}
.overCss{
background-color:#FEF2E8;  /* #EEF2FB这个将是鼠标高亮行的背景色*/
}
.clickCss{background-color:#A7CDF0;} /*3385ff*/

弹出新界面,在新界面执行方法后传参给调用界面,再执行调用界面的方法