How to Use an ASP.NET Textbox?
The best way to learn any type of programming is by example, so let's jump right in. We are going to build a page with a form containing an ASP.NET textbox for the user to enter their name, a button to submit that name, and a blank label. Then, we will demonstrate how to use the submitted value from the textbox to populate that label. The code for our page is as follows:
<form id="form1" runat="server">
What is your name? <br />
<asp:TextBox ID="txtMyName" runat="server" /> <br />
<asp:Button ID="btnChangeName" Text="Submit Name" PostBackURL="" runat="server" /><br />
<asp:Label runat="server" ID="lblMyName" />
Which will render like this:
We now have a form composed of an ASP.NET textbox and a button. When the button is clicked, it will post the values of each control in the form to the page defined by the PostBackURL property. The only active control in our form in this case is the ASP.NET textbox, and since the postback URL is blank it will post to the current page. Therefore we are submitting the text within the textbox back to the current page and reloading it. If you wanted to use the data from the form in a different page, you could change the PostBackURL property to point at that page.