Refresh parent list from popup in asp.net c #

I have a dropdwnlist control on my parent page - ASP.NET C #, when I click the button, a popup window opens to add a new value to the control.

[+]

On the PopUp - Save page, 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 on 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 saved in the database and the popup closes, but recently added data is not updated in the drop-down list. This works for IE, but not for Chrome.

Please, help..

0
javascript c # popupwindow
source share
2 answers

Change loadOptionLandlord 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; } 
0
source share

Can you check this feature?

 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 a js example to add an option to the JS BIN dropdown

0
source share

All Articles