Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function test()
    {
        var index=document.getElementById("DropDownList1").Selectedindex;
        switch(index)
             {
             case 1:
             alert("client1");
               break;
             case 2:
              alert("client2");
               break;
             default:

             }
    }




    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1"  runat="server">
            <asp:ListItem>client1</asp:ListItem>
            <asp:ListItem>client2</asp:ListItem>
        </asp:DropDownList>
        empid<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

.cs


C#
protected void Page_Load(object sender, EventArgs e)
   {
       TextBox1.Attributes.Add("onkeypress", "javascript:test()");
   }
Posted
Comments
Malli_S 14-Sep-12 3:57am    
What exactly is your problem ? Is that your test() not getting called or on selection of any item in dropdown list, you want the test() to fire?

Add some more description by selecting 'Improve question' option.
darshith 14-Sep-12 4:15am    
on selection of any item in dropdown list, i want the test() to fire?
@Malli_S
darshith 14-Sep-12 4:09am    
on selection of any item in dropdown list, i want the test() to fire?
@Malli_S

1 solution

If you want test() to be called on dropdown click/selection even you need to add event handler to dropdown list, not for textbox as u added.

C#
ListBox1.Attributes.Add("onchange", "javascript::test();")
 
Share this answer
 

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

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900