How to programmatically set the TextBox value and get the TextBox value in ASP.NET in VB.NET

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 and how the TextBox is used to set the Label.


<%@ Page Language=”vb” AutoEventWireup=”false” CodeBehind=”SetAndGetTextBox.aspx.vb”

Inherits=”TextBoxSamplesVB.SetAndGetTextBox” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>

<html xmlns=””>

<head runat=”server”>

<title> Set and get the TextBox value</title>



<form id=”form1″ runat=”server”>


<asp:Label ID=”lblOne” runat=”server” Text=”Now is :”></asp:Label>

<asp:TextBox ID=”tbTest” runat=”server”></asp:TextBox>

<br />

<asp:Label ID=”lblTwo” runat=”server” Text=”Label”></asp:Label>






Public Class SetAndGetTextBox

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim Value As String

Value = DateTime.Now.ToString

‘Set value to TextBox

tbTest.Text = Value

‘Get value from TextBox

lblTwo.Text = tbTest.Text

End Sub

End Class