Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value of textbox

How to set value of textbox?

I have this 1 textbox, and i want to set the default value is 0 so that when user not entering anythng my calculation still can.

like image 332
Who Me Avatar asked Feb 23 '12 09:02

Who Me


People also ask

What is a default value to a text box?

The DefaultValue property specifies text or an expression that's automatically entered in a control or field when a new record is created. For example, if you set the DefaultValue property for a text box control to =Now() , the control displays the current date and time.

What is the default size of textbox in HTML?

size. The size attribute is a numeric value indicating how many characters wide the input field should be. The value must be a number greater than zero, and the default value is 20.

How can you specify default text in an input field?

The value attribute specifies the value of an <input> element. The value attribute is used differently for different input types: For "button", "reset", and "submit" - it defines the text on the button. For "text", "password", and "hidden" - it defines the initial (default) value of the input field.

What is the default value of maxLength?

The default value of Input Email maxLength property is 524288.


2 Answers

This can either be done in the markup (.aspx) like:

<asp:TextBox id="txt" runat="server" Text="0" />

Or in the code-behind (.aspx.cs):

txt.Text = 0;

Or if you're using VB.NET:

txt.Text = 0

However, if you're doing a calculation based on this, you shouldn't rely on there always being a value in the textbox.

You could do:

Dim txtValue as Integer = 0
If IsNumeric(txt.Text) Then
   txtValue = txt.Text
End If
like image 192
Curtis Avatar answered Nov 15 '22 07:11

Curtis


If you want to use it with numbers, then you can tell the textbox that it should be with numbers, then "0" will be default.

<asp:TextBox ID="TB_Numbers" TextMode="Number" Text="0" runat="server"></asp:TextBox>
like image 41
Zeuthenjr Avatar answered Nov 15 '22 07:11

Zeuthenjr