2

I am writing an ASP.Net web application and am trying to set a default text value to a TextBox on a page load.

I want the page to load with a text value already entered into the TextBox. Unlike a placeholder I want it to be physical text in the TextBox. No matter what I try the closest I can get to is having the value of the TextBox to what I want but not the actual text.

I have been scouring the web looking for an answer and have had no luck. Any help will be highly appreciated.

2 Answers 2

1

In the markup:

<asp:TextBox ID="txtBox" runat="server" Text="My default text" />

Or in code-behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
       txtBox.Text = "My default text"
    End If
End Sub
Sign up to request clarification or add additional context in comments.

Comments

0

Asp.net code:

<asp:TextBox ID="TextBox1" runat="server" Text="hello" />

vb.net code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
   txtBox.Text = "hello"
End If

End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.