You can make the TextBox control readonly by setting its ReadOnly property to true. You can set this property in the .aspx page which contains the TextBox control, or programmatically from the code-behind. The next test .aspx page shows this:
<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”ReadOnlyTextBox.aspx.cs”
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
You can render the TextBox control to as password type by setting its TextMode property to Password. The next test .aspx page shows this:
TextBoxAsPassword.aspx
<%@ Page Language=”vb” AutoEventWireup=”false” CodeBehind=”TextBoxAsPassword.aspx.vb”
Inherits=”TextBoxSamplesVB.TextBoxAsPassword” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”https://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Password type TextBox</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:TextBox ID=”tbPassword” runat=”server” TextMode=”Password”></asp:TextBox>
The next example uses a test.aspx page named SetAndGetTextBox.aspx which has two asp:Label controls and one asp:TextBox control. In the code behind the local string variable value is use to read in it the system date and time by using:
Value = DateTime.Now.ToString
The rows in bold show how value is used to set the TextBox […]
The next example uses a test.aspx page named SetAndGetTextBox.aspx which has two asp:Label controls and one asp:TextBox control. In the code behind the local string variable value is use to read in it the system date and time by using:
value = DateTime.Now.ToString();
The rows in bold show how value is used to set the TextBox […]
When you want to write encoded text on the web page you should use the Literal control, because it does support a property that is not supported by the Label control: the Mode property. The property enables you to encode HTML content and accept any of the following three values:
– PassThrough—Displays the […]
The next code shows how you can attach an asp:Label control with the asp:TextBox. In this case when the user clicks the Label the application will focus on the TextBox.
TestAssociate.aspx
<%@ Page Language=”vb” AutoEventWireup=”false” CodeBehind=”TestAssociate.aspx.vb” Inherits=”TextChange.TestAssociate” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”https://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Associate a Label with a TextBox</title>
</head>
<body>
<form […]
You can apply CSS style from code behind by accessing the properties of the control with the help of its Id. Most of the CSS styles can be applied using the Font property and its sub properties of the Label control. However you can use ForeColor and BackColor directly from the Label control.
[…]
You can apply CSS style from code behind by accessing the properties of the control with the help of its Id. Most of the CSS styles can be applied using the Font property and its sub properties of the Label control. However you can use ForeColor and BackColor directly from the Label control.
TestApplyCSS.aspx
<%@ Page […]
TestPage (.aspx)
<%@ Page Language=”vb” AutoEventWireup=”false” CodeBehind=”TestPage.aspx.vb” Inherits=”TestChange.TestPage” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”https://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Change the text of the Label control from the code-behind</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:Label ID=”LabelTest” runat=”server” Text=”My test label”></asp:Label>
</div>
</form>
</body>
</html>
Test page code-behind (.vb)
‘
‘TestPage.apsx.vb
‘
Public Class TestPage
Inherits System.Web.UI.Page
Recommended ASP.NET Examples