I have dropdown on my page, I am changing selected value of dropdown from popup window using javascript. I have some logic in dropdown SelectedIndexChanged event, so I need to fire the SelectedIndexChanged event when dropdown selection changed from javascript.
+1
A:
Call onchange method like that at client side :
document.getElementById('yourDropdownsClientId').onchange();
EDIT : If you set your dropdown's AutoPostBack property to true, the code above will post your page to server, than your server side event will be called.
But If you want to call your event manually, you can all it anywhere in your page's codebehind like that :
myDropDownList_SelectedIndexChanged(null, new EventArgs());
Canavar
2009-06-17 14:00:40
but I want to fire server side dropdown SelectedIndexChanged event, I have my logic on server side.
Muhammad Akhtar
2009-06-17 14:19:16
but doing this document.getElementById('yourDropdownsClientId').onchange(); getting javascript Error.
Muhammad Akhtar
2009-06-18 07:41:48
A:
yeah...i think what Canavar said will work but it will have to look like this
document.getElementById('<%=yourDropdown.ClientId%>').onchange();
Eric
2009-06-17 14:04:25
+1
A:
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)
}
}
Olivier
2009-12-21 08:01:20
A:
actually its : document.getElementById('<%=yourDropdown.ClientId%>').change();
Justin
2010-07-02 18:52:17