Bootstrap FreeKB - Visual Studio - Variables
Visual Studio - Variables

Updated:   |  Visual Studio articles

When first learning variables, probably the easiest varabile to learn is one that hold's a string of text. In this example, let's say you have a page in Visual Studio named example.aspx, and you want to create a variable that contains the text "Hello World".


Create variable

In Design View, double left-click to open code behind. Adding Label1.Text = "Hello World" in code behind creates a variable named Label1 that displays the text Hello World.

VB

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
 Handles Me.Load  Label1.Text = "Hello World"
End Sub

 

C#

protected void Page_Load(object sender, EventArgs e){
    Label1.Text = "Hello World";
}

 


Use variable

To use the Label1 variable, the following markup will need to be added to the example.aspx page:

<asp:Label ID="Label1" runat="server"></asp:Label>

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 49adeb in the box below so that we can be sure you are a human.