提交前检查必填文本字段 [英] Checking of mandatory text fields before submission

查看:47
本文介绍了提交前检查必填文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要一个如何在单击提交按钮的表单上显示错误消息的示例。





必填项文本字段如下:



a。 txt_Name.Text ----名称

b。 txt_Date.Text ----当前日期

c。 txt_Amount.Text ----金额





如何对其进行编码以便测试所有3个字段





谢谢



我的尝试:



我看过的例子不清楚,我需要更清楚的采用

解决方案

对于WebForms,使用验证控件:

ASP.NET验证控件 [< a href =https://msdn.microsoft.com/en-us/library/debza5t0.aspxtarget =_ blanktitle =New Window> ^ ]



对于MVC,请使用验证数据注释:

添加验证| Microsoft Docs [ ^ ]


首先,不要使用文本框作为日期 - 使用DateTimePicker或日历(取决于您的环境)。这样,您可以将其默认为当前日期,并且不能输入日期。



对于其他人,请使用string.IsNullOrWhiteSpace [ ^ ]验证名称, double.TryParse [ ^ ]验证量。

Need an example of how to display error message on a form with a number of mandatory fields on click of submit button.


The mandatory text fields are as follows :

a. txt_Name.Text ----Name
b. txt_Date.Text ----Current Date
c. txt_Amount.Text ----Amount


How do I code it such that it tests all 3 fields


Thanks

What I have tried:

The examples I have looked at are not clear and I need a clearer one to adopt

解决方案

For WebForms, use the validation controls:
ASP.NET Validation Controls[^]

For MVC, use the validation data annotations:
Adding Validation | Microsoft Docs[^]


Firstly, don't use a textbox for the date - use a DateTimePicker or a Calendar (depending on your environment) instead. That way, you can default it to the current date, and they can't not enter a date.

For the others, use string.IsNullOrWhiteSpace[^] to validate the name, and double.TryParse[^] to validate the amount.


这篇关于提交前检查必填文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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