文本框的默认值 [英] Default value of textbox

查看:109
本文介绍了文本框的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置文本框的值?

How to set value of textbox?

我有这个1文本框,我想要设置的默认值是0,这样,当用户不输入仍然anythng我的计算可以。

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.

推荐答案

这既可以在标记进行(的.aspx),如:

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

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

或在code-背后(.aspx.cs):

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

txt.Text = 0;

或者,如果你使用VB.NET:

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.

您可以这样做:

Dim txtValue as Integer = 0
If IsNumeric(txt.Text) Then
   txtValue = txt.Text
End If

这篇关于文本框的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆