ASPAlliance.com : The #1 Active Server Pages .NET Community The #1 ASP.NET Community
Search   Search

Subscribe   Subscribe

Powered by ORCSWeb Hosting


Site Stats


Powered By ASP.NET
 
Featured Sponsor

Featured Columnist


Featured Book
Professional ASP.NET Web Services
Professional ASP.NET Web Services

Find Prices
Sample Chapter


New! asp.netPRO

We publish our articles in the standard RSS format.

Powerful .NET Email Component

Code Sharing Software

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 ..

  1. Get an input from the user
  2. Create a textarea
  3. 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

 Copyright © 2000-2003 ASPAlliance.com  Page Rendered at 11/7/2009 7:39:30 PM