用于c#asp.net中客户端的文本框验证 [英] for textbox validation at client side in c# asp.net

查看:81
本文介绍了用于c#asp.net中客户端的文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题依赖于javascript。



我有用户控制表单和aspx表单,如果在user-controland中有4个文本框我想查看空白从aspx表格验证文本框,其中c#asp.net中有一个按钮



onclientclick



plz尽快回复

the question is releted to javascript.

I have user-control form and aspx form, if there are 4 textbox in user-controland i want to check blank validation of textbox from aspx form where there is an one button in c# asp.net

onclientclick

plz reply as soon as possible

推荐答案

假设我们创建的用户控件只有一个名为'txt'的asp:文本框,我们必须在页面中验证它。



Suppose we create a user control that has only asp:text box named 'txt', and we have to validate it in our page.

<myText:Textbox ID="txt" runat="server" Visible="true"  />
    <asp:Button ID="btnSumbit" runat="server" Text="Validate user control" OnClientClick="javascritp:return IsFilled()" />







您可以使用以下JavaScript来获得该控制权。






You can use the following JavaScript to get that control.

var a=document.getElementById('form1').elements("txt


txt );
if (a.value == ' '
{
alert( 请输入值 );
return false;
}
txt"); if(a.value=='') { alert("please enter value"); return false; }







问候




Regards






在客户端验证内容是个坏主意。如果有人在浏览器中禁用JavaScript,则您不再验证文本框。所以,总是在服务器端验证内容!



在这种情况下,使用 RequiredFieldValidator ,这是服务器-side:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator%28v=vs.110%29.aspx [ ^ ]

http://asp.net-tutorials.com/validation / required-field-validator / [ ^ ]

http://www.devmanuals.com/教程/ MS / aspdotnet / requiredfieldvalidator.html [< a href =http://www.devmanuals.com/tutorials/ms/aspdotnet/requiredfieldvalidator.html\"target =_ blanktitle =New Window> ^ ]
Hi,

It's a bad idea to validate stuff at client-side. If someone disables JavaScript in his browser, then you don't longer validate the text box. So, ALWAYS validate stuff at server-side!

In this case, use a RequiredFieldValidator, which is server-side:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator%28v=vs.110%29.aspx[^]
http://asp.net-tutorials.com/validation/required-field-validator/[^]
http://www.devmanuals.com/tutorials/ms/aspdotnet/requiredfieldvalidator.html[^]


这篇关于用于c#asp.net中客户端的文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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