Home > DeveloperSection > Forums > How to implement click event on textbox
john rob

Total Post:108

Points:756
Posted on    November-27-2014 1:02 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 582  View(s)
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



Pravesh Singh

Total Post:411

Points:2881
Posted on    November-27-2014 1:54 AM

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>


Don't want to miss updates? Please click the below button!

Follow MindStick