Want to fire Dropdown SelectedIndexChanged Event in Javascript

46,815

Solution 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)
}
}

Solution 2

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());
Share:
46,815
Muhammad Akhtar
Author by

Muhammad Akhtar

Senior Software Engineer MCTS - Microsoft Certified Technology Specialist toakhtar - at - hotmail - .com Cell # : 00923014728930 View my MCP Certifications http://stackoverflow.com/tags/asp.net/topusers http://stackoverflow.com/search?tab=votes&q=user%3a97010%20%5basp.net%5d http://www.linkedin.com/profile/view?id=48514505&trk=tab_pro

Updated on October 24, 2021

Comments

  • Muhammad Akhtar
    Muhammad Akhtar over 2 years

    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.