简体   繁体   English

从ASP.NET C#中的弹出窗口刷新父下拉列表

[英]Refresh parent dropdownlist from popup in asp.net c#

I have a dropdwnlist control in my parent page - ASP.NET C#, on click of button there is a popup opening to add new value to the control. 我的父页面-ASP.NET C#中有一个dropdwnlist控件,单击按钮时会弹出一个弹出窗口,用于向该控件添加新值。

[+] [+]

In PopUp page - Save button , I have the following code : 在弹出页面-保存按钮中,我有以下代码:

Response.Write("<script>opener.loadOptionLandlord('" + stid  + "','" + strLandlorconn_dbame + "');</script>");
Response.Write("<script>window.close();</script>");

where loadOptionLandlord is a function in my parent page : 其中loadOptionLandlord是我的父页面中的一个函数:

function loadOptionLandlord(val,txt)
        {
            var opt = document.createElement('<option value="'+ val +'">');
            opt.innerText = txt;
            var sCtrl = document.getElementById('<%= ddlLandlord.ClientID %>');

            sCtrl.options[sCtrl.options.length] = new Option(txt, val, false, true);

        }

The value is being saved to the database and the popup window is closing , but the newly added data is not refreshing in the dropdownlist. 该值已保存到数据库,并且弹出窗口正在关闭,但是新添加的数据在下拉列表中未刷新。 This is working for IE, but not for Chrome. 这适用于IE,但不适用于Chrome。

Please help .. 请帮忙 ..

can you check this function ? 您可以检查此功能吗?

function loadOptionLandlord(val,txt)
        {
            // Those create element not needed and its a wrong 
            // because you directly add option to select
            //var opt = document.createElement('<option value="'+ val +'">');
           // opt.innerText = txt;
            var sCtrl = document.getElementById('<%= ddlLandlord.ClientID %>');

            sCtrl.options[sCtrl.options.length] = new Option(txt, val, false, true);

        }

here is sample js to add option on drop-down JS BIN 这是示例js在下拉JS BIN上添加选项

Change your loadOptionLandlord as below 如下更改您的loadOptionLandlord

function loadOptionLandlord(val,txt)
        {
            var opt = document.createElement("option");            
            var sCtrl = document.getElementById('<%= ddlLandlord.ClientID %>').options.add(opt);
            opt.text = txt;
            opt.value = val;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM