Refresh parent dropdownlist from popup in asp.net c#

蓝咒 提交于 2020-01-06 13:53:12

问题


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.

[+]

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 :

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.

Please help ..


回答1:


Change your loadOptionLandlord as below

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



回答2:


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



来源:https://stackoverflow.com/questions/26623479/refresh-parent-dropdownlist-from-popup-in-asp-net-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!