Textbox Web Server Control
We can get inputs from user in variety of ways. One of the way is through textbox.
In this session, we will see how to ..
- Get an input from the user
- Create a textarea
- Get passwords as input
Textbox and Button
In the following example the usage of label web server control is explained. The
property "Text" is used to assign a value (label) to the label control. We also have a
button control which is used to submit the value back to the page.
<html>
<head>
<title>Textbox Web Server Control - by Das
<script language="VB" runat="server">
Sub MySub(sender As Object, e As EventArgs)
lblMsg.text = "Is Your First Name, " & txtFname.text & " ?"
End Sub
</script>
</head>
<body style="font: 10pt verdana">
<h3 align=center>ASP.NET Textbox Server Control</h3>
<form ID="Form1" runat=server>
First Name <asp:TextBox id=txtFname Runat=server />
<asp:Button Text="Submit" OnClick="MySub" Runat=server />
<asp:Label id=lblMsg ForeColor="#ff0000" Runat=server />
</form>
</body>
</html>
|
Test this Script
Password
If we have web application, then we will definitely have a Login module. For any login
password is a must. In ASP .NET we have to make use of the property, textmode=password.
We can access the password value by saying, txtPwd.Text, were txtPwd is a textbox
of type password. It should be also noted that, to concatinate a string, we can use the
operator += just as in C/C++.
<html>
<head>
<title>Textbox Web Server Control - by Das</title>
<script language="VB" runat="server">
Sub MySub(sender As Object, e As EventArgs)
lblMsg.text = "<br>Is Your First Name, <b>" & txtFname.text & " </b>?"
lblMsg.text += "hmmm, you typed the password, <b>" & txtPwd.text & " </b>right ?"
End Sub
</script>
</head>
<body style="font: 10pt verdana">
<h3 align=center>ASP.NET Textbox Server Control</h3>
<form ID="Form1" runat=server>
First Name <asp:TextBox id=txtFname Runat=server />
Password <asp:TextBox id=txtPwd TextMode=Password Runat=server />
<asp:Button Text="Submit" OnClick="MySub" Runat=server />
<asp:Label id=lblMsg ForeColor="#ff0000" Runat=server />
</form>
</body>
</html>
|
Test this Script
TextArea
In Classic ASP, we have the tag <textarea> to accept values in text area. The same can
be achieved in ASP.NET using the textbox web control. We have set the property, "textmode",
to "multiline", such as textmode=MultiLine. You can also specify the rows and
columns that you may need.
<html>
<head>
<title>Textbox Web Server Control - by Das</title>
<script language="VB" runat="server">
Sub MySub(sender As Object, e As EventArgs)
lblMsg.text = "<br>Is Your First Name, <b>" & txtFname.text & " </b>?"
lblMsg.text += "<br>Well, your hobbies seems to be, <b>" & txtHobby.text & "</b>"
End Sub
</script>
</head>
<body style="font: 10pt verdana">
<h3 align=center>ASP.NET Textbox Server Control</h3>
<form ID="Form1" runat=server>
First Name <asp:TextBox id=txtFname Runat=server />
Your hobbies <asp:TextBox id=txtHobby TextMode=MultiLine Rows=10 Columns=60 Runat=server />
<asp:Button Text="Submit" OnClick="MySub" Runat=server />
<asp:Label id=lblMsg ForeColor="#ff0000" Runat=server />
</form>
</body>
</html>
|
Test this Script
Conclusion
Another aspect that you may need to note in these examples is, when we click the submit
button, all the values are retained in the form without any additional coding. This is
the most important feature, Maintaining State, of ASP.NET
Send your comments to das@aspalliance.com
Back to Tutorial
|