ASP.NET - autopost back =true, dropdown,javascript

Asked By Ali Khan on 18-Jun-12 10:58 AM
Hi folks,

1)I want to use alert of javascript on drop d own to display by alert the text of drop down which is selected but the problem is that it is auto post back true.I am a new one kindly help me.. &
2)& further more i want to ask in how many ways i can do that ?
dipa ahuja replied to Ali Khan on 18-Jun-12 05:27 PM

<script type="text/javascript">
  function Validate() {
    var ddl = document.getElementById('<%=DropDownList1.ClientID%>');
    var option = ddl.options[ddl.selectedIndex];
    if (option.value == 0) {
      alert('select value from dropdown');
      return false;
    else {
      return true;
  <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return Validate();" />
Jitendra Faye replied to Ali Khan on 19-Jun-12 02:44 AM
Simply use this code-

 <script type="text/javascript">
      function show() {
        var drp = document.getElementById('<%=DropDownList1.ClientID%>');
        return false;

<asp:DropDownList ID="DropDownList1" runat="server">

<asp:Button ID="Button7" runat="server" Text="test" OnClientClick="return show();" />

Try this and let me know.