Want to remove Dropdown SelectedIndexChanged event in Javascript

I have a drop-down list on my page, I am changing the selected dropdown value from a popup using javascript. I have some logic in the SelectedIndexChanged dropdown event, so I need to fire the SelectedIndexChanged event when the dropdown selection has changed from javascript.

+5
source share
4 answers
document.getElementById('<%= yourDropdown.ClientID %>').onchange();

This should work if you still get some error, you can try the following:

setTimeout('__doPostBack(\'yourcontrolClientSideID\',\'\')', 0);

yourcontrolClientSideID - identifier of the visualized client identifier.

+9
source

, :

document.getElementById('yourDropdownsClientId').onchange();

EDIT: AutoPostBack true, , .

, :

myDropDownList_SelectedIndexChanged(null, new EventArgs());
+1

Here is a working example:

function fireEvent(element,event){
if(document.createEvent){
 // dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); // event type,bubbling,cancelable
return !element.dispatchEvent(evt);
}
else{
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent(’on’+event,evt)
}
}
+1
source

yes ... I think Canavar said it would work, but it would look like this.

document.getElementById('<%=yourDropdown.ClientId%>').onchange();
0
source

All Articles