Parag’s Den

Dedicated to my adored friends…..

Textbox Web Server Control

Posted by paragdongre on November 6, 2007


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>

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>

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>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: