Click here to Skip to main content
14,641,849 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Experts,

I want to call some javascript code from my aspx page on the selected index changed event of drop down list

<asp:dropdownlist id="DropDownList1" runat="server" width="163px" onselectedindexchanged="how to call javascript from here">
</asp:dropdownlist>



Regards,
Prashant
Posted
Updated 11-Aug-10 19:42pm
v2
Comments
Ankur\m/ 12-Aug-10 1:42am
   
Edited for formatting.
Rate this:
Please Sign up or sign in to vote.

Solution 3

Or, how about a little JQuery? :)

$(document).ready(function() {
        $("#<%=DropDownList1.ClientID%>").change(function() {
            //Your code goes here
        });
    });
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

you can use onchange attribute for doing this.
Use this in the code behind if not a post back,

DropDownList1.Attributes.Add("onchange","Method();");


or alternatively you can directly give this attribute inline.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

You can write:
<asp:DropDownList ID="DropDownList1" runat="server" Width="163px" onchange="javascript:functionName();"/>
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

Create Function in Javascript like

function onSelectedindexOccured()
{
 // To Do
}


and from your Aspx page on selectedindexchange event write

<br />
"javascript:onSelectedindexOccured"<br />





thanks
Hiren Solanki
   
Comments
Ankur\m/ 27-Aug-10 8:00am
   
Reason for my vote of 1
Absolutely rubbish. Do you understand that Javascript is a client side technology. The event you are talking about needs postback. And why on earth would you go back about 15 days and answer a question which is already answered with nothing substantial to add??
Hiren solanki 27-Aug-10 8:07am
   
just knowledge sharing
Thanks Ankur /m/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100