学习ASP.NET八天入门:第二天
来源:cnplayer.com 时间:2007-08-07 13:24:00
学习目的:
掌握文本框的用法
初次接触try…catch…语法
今天内容很轻松,用一个例子,输入年月日,判断输入是否正确
图片如下:
用个文本框,ID分别为txtYear,txtMonth,txtDate;
检验按钮的代码为:private void btnCheck_Click(object sender, System.EventArgs e)
{
int year, month, date;
// 先把输入的字符转成int类型,如果非数字型,
// 会触发错误
try
{
year = Convert.ToInt32(txtYear.Text);
month = Convert.ToInt32(txtMonth.Text);
date = Convert.ToInt32(txtDate.Text);
}
catch
{
labCheckInfo.Text = "输入的是非数字字符。";
return;
}
// 如果第一步检验合格,就把输入的数字转化为日期格式
// 如果不符合日期格式即引发错误
try
{
DateTime dt = new DateTime(year, month, date);
}
catch
{
labCheckInfo.Text = "输入的数字不符合日期格式";
return;
}
labCheckInfo.Text = "输入正确";
}
嗯,补充一下,关于StringBuider
在处理字符串的时候很多人喜欢+=,其实对于string来说,一旦定义了就无法更改了
所谓的+只是新建的一个新的string变量并赋值
所以对于尽量使用StringBuider的Append的方法,这样将大量的节省服务器的资源相关阅读:
标签:ASP.net,入门,文本框,try
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server触发器及触发器中的事务学习
2024-01-27 08:48:02
![](https://img.aspxhome.com/file/2023/2/116292_0s.png)
pandas 使用insert插入一列
2023-03-24 23:51:40
![](https://img.aspxhome.com/file/2023/2/133272_0s.jpg)
使用python实现下拉选择框和页签的方法
2021-10-01 04:07:41
![](https://img.aspxhome.com/file/2023/1/118541_0s.jpg)
python 3调用百度OCR API实现剪贴板文字识别
2022-12-13 19:01:14
DjangoRestFramework 使用 simpleJWT 登陆认证完整记录
2021-03-29 18:34:12
![](https://img.aspxhome.com/file/2023/1/76001_0s.png)
python遍历字符串中每一个字符的4种方式
2022-12-21 07:33:03
P3P 和 跨域 (cross-domain) cookie 访问(读取和设置)
2011-04-02 10:42:00
Python数据可视化实现多种图例代码详解
2022-02-11 04:01:38
![](https://img.aspxhome.com/file/2023/5/103665_0s.jpg)
Thinkphp结合ajaxFileUpload实现ajax异步图片传输全套代码
2023-06-14 04:01:53
python机器学习使数据更鲜活的可视化工具Pandas_Alive
2022-09-26 04:57:12
![](https://img.aspxhome.com/file/2023/8/112968_0s.png)
ExtJs事件机制基本代码模型和流程解析
2024-05-03 15:59:14
Mysql常用命令行大全
2009-01-15 16:34:00
MySQL服务自动停止的解决方法
2024-01-13 13:38:14
![](https://img.aspxhome.com/file/2023/0/67580_0s.png)
如何在 IE 中使用 HTML5 元素
2009-06-14 19:44:00
Python编程中使用Pillow来处理图像的基础教程
2021-07-20 10:53:19
深入了解JavaScript代码覆盖
2024-05-11 09:43:09
![](https://img.aspxhome.com/file/2023/3/125943_0s.png)
在Ubuntu 20.04中安装Pycharm 2020.1的图文教程
2022-05-28 23:03:48
![](https://img.aspxhome.com/file/2023/7/135057_0s.jpg)
完美解决Python matplotlib绘图时汉字显示不正常的问题
2023-09-28 05:30:55
![](https://img.aspxhome.com/file/2023/1/62901_0s.jpg)
python实现人机对战的井字棋游戏
2023-02-11 15:37:45
![](https://img.aspxhome.com/file/2023/3/133753_0s.jpg)
MySQL安装配置以及安装失败解决过程
2024-01-13 18:55:28
![](https://img.aspxhome.com/file/2023/1/124891_0s.png)