Click here to Skip to main content
15,893,923 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want a dropdown menu to be visible only when i click on the text box.
Is this possible? I can find no such click event in asp.net
Posted

Well, first of all read what a button click is: Button.Click Event[^]

Now, there is only one click event (not various types of.)

In your click event, just make your dropdown visible. Something like:
myDropdown.Visible = true;

If you want to show the dropdown visiblty without complete postback, then you can use JavaScript for the same. Use Button OnClientClick proerty, set the Javascript function that would be called on click of the button. In the Javascript function, just show the dropdown or any control you want to.
 
Share this answer
 
C#
Here is a solution for this prob

http://devdex.wordpress.com/2012/05/25/onclick-event-for-text-box-in-asp-net-with-c/
 
Share this answer
 
Hii,

You can solve this problem with the help of JavaScript:-


Step1:- Create a TextBox:-
ASP.NET
<input type="text"  runat="server"  önclick="show()" />


or

ASP.NET
<asp:TextBox ID="txtShowMenu" onclick="show()"  runat="server"></asp:TextBox>



Here you find a Onclick Event:- show() :- to call the js function



Step 2:- add a Menu:- and set iys disply property none:- display:none


ASP.NET
<asp:Menu ID="Menu1" runat="server" Width="152px" style="display:none;">
            <Items>
                <asp:MenuItem Text="Menu1" Value="New Item">
                    <asp:MenuItem Text="Submenu1" Value="Submenu1"></asp:MenuItem>
                </asp:MenuItem>
            </Items>
        </asp:Menu>



Step 3:


Write the js code



JavaScript
<script language="javascript" type="text/javascript" >

function show()
   {
   document.getElementById("Menu1").style.display='';
   }

</script>


The Whole Sample:->
ASP.NET
<head  runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript" >
    function show()
    {
    document.getElementById("Menu1").style.display='';
    }
    
    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
   <%-- <input type="text"  runat="server"  önclick="show()" />--%>
   
   
   <asp:TextBox ID="txtShowMenu" onclick="show()"  runat="server"></asp:TextBox> <br />
        <asp:Menu ID="Menu1" runat="server" Width="152px" style="display:none;">
            <Items>
                <asp:MenuItem Text="Menu1" Value="New Item">
                    <asp:MenuItem Text="Submenu1" Value="Submenu1"></asp:MenuItem>
                </asp:MenuItem>
            </Items>
        </asp:Menu>
    </div>
    </form>
</body>
 
Share this answer
 
v2
Comments
Sandeep Mewara 19-Jul-10 14:20pm    
Reason for my vote of 1
Asp:TextBox Click property would search for server method and not Javascript method. You need to use OnClientClick as I have mentioned in my reply. Currently, your code would throw an error that Show() is not defined on the server side.
Can you use ajax pop controlls
 
Share this answer
 

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



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