2012-09-20 3 views
14

Come utilizzare selectedIndexChanged dal droplist di asp.net in clientSide e ServerSide?Come utilizzare l'elenco a discesa SelectedIndexChanged in clientSide e ServerSide

In clientide, desidero chiamare javascript funcition!

<script type="text/javascript"> 
function changeCursor() { 
    document.body.style.cursor="progress"; 
} 
</script> 

<asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word" AutoPostBack="True" OnSelectedIndexChanged="SelectedChange"> 
</asp:DropDownList> 

SelectedChange è un nome di funzione in clientide!

Grazie per l'aiuto!

risposta

22

Aggiungi il tuo cliente nome della funzione a fianco in OnChange eventi di discesa, come di seguito:

<asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word" 
     AutoPostBack="True" OnSelectedIndexChanged="SelectedChange" 
     onchange="changeCursor()"> 
</asp:DropDownList> 
12

In HTML (aspx)

<asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word" AutoPostBack="True" 
     OnSelectedIndexChanged="SelectedChange" onchange="YourChangeFun(this);"> 
</asp:DropDownList> 

in JavaScript

<script type="text/javascript"> 
     function YourChangeFun(ddl) 
     { 
     alert(ddl.selectedIndex); 
     } 
</script> 
1

Prima sostituzione AutoPostBack = "false" e fornisce onchange = "js function()" e rimuove l'evento di modifica dell'indice selezionato.