Reputation: 305
Is there any ways to make a text box visible when user click a button? What I meant here is, user will only see the text box when button is clicked. Thanks in advance for help me. Have a good ones.
Upvotes: 2
Views: 7622
Reputation: 33
Is this a straightforward question or have I missed something?
By default, a textbox is visible. In the properties, you can set this to false (i.e., to make it invisible).
Then add a button to the panel.
Then code-behind button is as simple as:
textbox1.visible = true (this is vb code)
Is there anything else to this question or have I missed something?
Upvotes: 0
Reputation: 151
It's better to make these operations client side. In this way you are not sending the page to the server for this simple operation.
Add the onclick trigger to the button to make the text box visible
<input type="button" value="Click Me!" onclick="javascript:document.all['txtArea'].display='';" />
<input type="text" value="Some text..." style="display:none;" id="txtArea" />
example: http://jsfiddle.net/r54Et/
The same method can be applied to the server controls.
Update: If you are using server controls asp:... and have issue to find the id of textbox element, asp.net 4.0+ supports static names. It means that you can set a fix name for your element. Another workaround is that asp.net saves the client generated id inside ClientID property. So in this case we will have:
<input type="button" value="Click Me!" onclick="javascript:document.all['<%=txtArea.ClientID%>'].display='';" />
<asp:textbox tunat="server" Text="Some text..." id="txtArea" ..... />
Upvotes: 0
Reputation: 1531
If you are talking about web. Use jquery or javascript on document load to hide textbox and on a button click show textbox using the below code.
$(document).ready(function(){
$('#textBoxClientID').hide();
});
$('#buttonClientID').click(function(){
$('#textBoxClientID').show();
});
Upvotes: 0
Reputation: 22323
On page load set:
TextBox1.Visible = false;
and in button click:
protected void Button1_Click(object sender, System.EventArgs e)
{
TextBox1.Visible = true;
}
Upvotes: 0
Reputation: 17724
Make the button Visible on button Click event.
Double click on the button to add a Click event handler.
Your code should look as follows:
private void btnShow_Click(object sender, EventArgs e)
{
txtBox.Visible = true;
}
If you don't want the whole page to refresh on doing this, you may want to wrap these controls inside an updatePanel
Refer: Introduction to the UpdatePanels
Upvotes: 4
Reputation: 15557
Use styling:
textBox.Style.Add("visibility", "hidden");
textBox.Style.Add("display", "none");
And once clicked the button reverse it again.
Upvotes: 0