文本框为空字段给出错误 [英] Textbox empty field gives error

查看:150
本文介绍了文本框为空字段给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文本框中插入值

I want to insert the value in textbox

int totalexp = Int32.Parse(txtTotalExpPer.Text);



但是,如果字段为空,则会出现错误

[edit]添加了预标记c#代码,并且未选中将我的内容作为纯文本而不是HTML 进行处理-PES [/edit]



but if field is empty then it gives the error

[edit]pre tag c# code added and Treat my content as plain text, not as HTML is unchecked - PES[/edit]

推荐答案

Use it
int totalexp ;

int.tryParse(txtTotalExpPer.Text,out totalexp )


看看TryParse. http://msdn.microsoft.com/en-us/library/f02979c7.aspx [ ^ ]

祝你好运!
Have a look at TryParse. http://msdn.microsoft.com/en-us/library/f02979c7.aspx[^]

Good luck!


使用需求验证或在类型转换之前检查.......
Use require validation or check before type conversion .......


这篇关于文本框为空字段给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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