Wednesday, 27 June 2012

Beginning .Net : How to programmatically set the TextBox value and get the TextBox value with C# Examples and VB.Net Examples ?

You can set and get textbox value programmatically using C# and VB.Net. Every .Net Beginners needs to know this.
You can use "Text"  property of textbox to set and get value of textbox.

Here is example of this.
This example is in both C# .Net Programming and VB.Net Programming.
In this example we have one textbox it's id is "txtProductName".

ASPX Code : 
        <asp:TextBox runat="server" ID="txtProductName"></asp:TextBox>
        <br />
        <asp:Label runat="server" ID="lblProductName"></asp:Label>


C# Example :
        //Set textbox value
        txtProductName.Text = "ASP.net book";

        //Get textbox value and display in label
        lblProductName.Text = "Product Name : " + txtProductName.Text.Trim();

VB.net Example :
        ''Set textbox value
        txtProductName.Text = "ASP.net book"

        ''Get textbox value and display in label
        lblProductName.Text = "Product Name : " + txtProductName.Text.Trim()

Output : 



You can use Text.Trim() method to remove extra whitespace from left and rights side of text.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.


No comments:

Post a Comment