.net中window.open弹出窗口,更新数据之后,不刷新父页面,同时更新数据

        在做项目时,遇到这样的问题,用window.open弹出窗口,在子窗口更新数据,其中的一个字段值的数据是显示在父页面的某个dropdownlist中的,不需要刷新父页面,实时的更新父页面的dropdownlist中的值

具体如下:

添加:

父窗口函数
  
 function showInfo(id, name) {
//新建元素插入
            var option = document.createElement("Option");
            option.text = name;
            option.value = id;
            var ddl = document.getElementById("ddlContingencyPlanType");
            ddl.add(option);
        }

 

子窗口(后台实现或者ajax实现,成功之后回调函数,传入参数):
 function AddContingencyPlanType(id, name) {
            alert("添加成功");
//父页面调用函数
            window.opener.showInfo(id, name);
            window.close();
 
        }

  

更新(方法跟添加一样),在子窗口:
function updateType(id, name) {
            alert("更新成功");
//获取父页面控件,当value值相同时才更新
            var ddl = window.opener.document.getElementById("ddlContingencyPlanType");
            var count = ddl.length;
            for (var i = 1; i < count; i++) {
                if (ddl[i].value == id) {
                    ddl[i].text = name;
                }
            }
        }

 

在子窗口删除(ajax实现):
function deleteContingencyPlanType(typeId) {
            if (confirm("确定删除吗?")) {
                var obj = {
                    "id": typeId
                };
                $.ajax({
                    type: "GET",
                    data: obj,
                    url:  '../Message/DeleteTypeHandler.ashx?t=' + (new Date()).valueOf(),//加参数
                    dataType: "text",
                    success: function (result) {
                        if (result == "Success") {
                            alert("删除成功");
                            location.href = "TypeListForm.aspx";
                            var ddl = window.opener.document.getElementById("ddlPlanType");
                            var count = ddl.length;
                            for (var i = 1; i < count; i++) {
                                if (ddl[i].value == typeId) {
                                    ddl.options.remove(i);
                                    count = count - 1;
                                }
                            }
                        }
                        else {
                            alert("删除失败");
                        }
 
                    }
                });
            }
        }

 

posted @ 2013-01-11 11:35  九九哥  阅读(971)  评论(0)    收藏  举报