HOW TO IMPLEMENT CLICK EVENT ON TEXTBOX

john rob

Total Post:108

Points:756
Posted by  john rob
 1028  View(s)
Ratings:
Rate this:

In my web application I need a functionality so that when users click on textbox to input values, it should make the button and the other fields visible? 

I am using the code provided below but, could not get it working. 

C#: 

protected void TextBox1_Click(object sender, EventArgs e)
{
    ButtonSearch.Visible = true;
}

ASP.Net: 

<asp:TextBox ID="TextBox1"runat="server" OnTextChanged="TextBox1_TextChanged"
OnClick="TextBox1_Click"></asp:TextBox>
<asp:Button ID="ButtonSearch"runat="server" OnClick="ButtonSearch_Click" Text="Search" Visible="False" />

How to accomplish this? 

Thanks

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: How to implement click event on textbox

    Hi John, 


    Set AutoPostback="True". This way the event will be fired server-side, and the button will become visible. 

    <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"     OnClick="TextBox1_Click" AutoPostBack="true"></asp:TextBox>

    However, if you only want to toogle visility of a button, you really should considerate javascript. This will save a trip back to the server. 

    <asp:TextBox onclick="txtBox1_ClientClicked()"ID="TextBox1" runat="server"
    OnClick="TextBox1_Click"></asp:TextBox> 
    <asp:Button ID="ButtonSearch" runat="server" OnClick="ButtonSearch_Click" Text="Search" style="display:none;" /> 
    <script type="text/javascript">
        function txtBox1_ClientClicked(){
            var theButton= document.getElementById('<%=ButtonSearch.ClientID%>');        theButton.style.display = 'block';
        }
    </script>

      Modified On Apr-07-2018 01:19:44 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!