如何在文本框C#,asp.net中添加单击事件 [英] How can you add a click event in the text box, C# , asp.net

查看:327
本文介绍了如何在文本框C#,asp.net中添加单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望下拉菜单仅在单击文本框时可见.
这可能吗?我在asp.net

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

推荐答案

没有找到这样的单击事件,首先,请阅读按钮单击是什么:
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.


Here is a solution for this prob

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


Hii,

您可以借助JavaScript解决此问题:-


步骤1:-创建一个文本框:-
Hii,

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


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







or

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




在这里,您会发现一个Onclick事件:-show():-调用js函数



步骤2:-添加菜单:-并设置iys disply属性none:-display:none





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: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>




步骤3:


编写js代码






Step 3:


Write the js code



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

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

</script>



整个样本:->



The Whole Sample:->

<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>


这篇关于如何在文本框C#,asp.net中添加单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆