winform上有全局验证吗?
我知道如何在我的winforms中使用ErrorProvider。我是吗?我在值中验证了
并在验证事件中设置了ErrorProvider。如果没有
有效,我设置e.Cancel = True。我清除了
验证事件中的ErrorProvider。
有没有办法知道所有经验证的控件是否通过验证
用户单击确定按钮?在ASP.Net中有Page.IsValid
方法。在winforms中是否有类似的东西,或者我仍然需要
写一个整体验证例程以点击按钮点击?我试过了
Me.Validate(),但总是返回true ...我想我必须在表单validate事件中输入我的
最终验证?
在我看来,ASP.Net应用程序中的表单验证要容易得多。
I know how to use the ErrorProvider in my winforms..or do I? I validate
the values and set the ErrorProvider in the validating event. If not
valid, I set e.Cancel = True. I clear the ErrorProvider in the
validated event.
Is there a way to know if all validated controls pass validation when
the user clicks an OK button? In ASP.Net there''s the Page.IsValid
method. Is there something similar in winforms, or do I still have to
write an overall validate routine to fire on the button click? I tried
Me.Validate(), but that always returned true...I guess I have to put my
final validations in the forms validate event?
It seems to me that form validation is much easier in ASP.Net apps.
JJButer,
区别在于Winform的使用与
WebForm的使用不同。一个webform就像一个经典的简单非智能工作站。
它发送所有数据,经过验证,如果错误,则发送消息
返回。
在winforms中检查每一个控件的使用情况以及
验证是否完成,这使得它在大多数情况下更加愉快
对于用户来说,因为他们已经填满了所有已准备好的方框,并且通常不会再出现任何错误。可以有一些(商业)
规则,但这可能意味着这样做是因为只能检查数据上的全部视图
。
您可以在使用JavaScript的网页上模拟此行为,但绝不会像winform一样罚款。
我希望这个给出了一个想法,
Cor
< jj ****** @ hotmail.comschreef在bericht
news:11 ********************** @ m73g2000cwd.googlegr oups.com ...
JJButer,
The difference is that the use of a Winform is different than from a
WebForm. A webform behaves as a classic simple non intelligent workstation.
It sends all data, that is validated and if it is wrong a message is send
back.
In winforms is the usage that every single control is checked and that the
validating is done on that, this makes it in most siutations more pleasant
for the users because as they have filled all the boxes they are ready and
normally no error cannot be throwed anymore. There can be some (business)
rules however that can mean that this is done because only the overal view
on the data can be checked.
You can simulate this behaviour on a webpage with JavaScript, but never as
fine as with a winform.
I hope that this gives an idea,
Cor
<jj******@hotmail.comschreef in bericht
news:11**********************@m73g2000cwd.googlegr oups.com...
>我知道如何在我的winforms中使用ErrorProvider。我是吗?我在值中验证了
并在验证事件中设置了ErrorProvider。如果没有
有效,我设置e.Cancel = True。我清除了
验证事件中的ErrorProvider。
有没有办法知道所有经验证的控件是否通过验证
用户单击确定按钮?在ASP.Net中有Page.IsValid
方法。在winforms中是否有类似的东西,或者我仍然需要
写一个整体验证例程以点击按钮点击?我试过了
Me.Validate(),但总是返回true ...我想我必须在表单validate事件中输入我的
最终验证?
在我看来,ASP.Net应用程序中的表单验证要容易得多。
>I know how to use the ErrorProvider in my winforms..or do I? I validate
the values and set the ErrorProvider in the validating event. If not
valid, I set e.Cancel = True. I clear the ErrorProvider in the
validated event.
Is there a way to know if all validated controls pass validation when
the user clicks an OK button? In ASP.Net there''s the Page.IsValid
method. Is there something similar in winforms, or do I still have to
write an overall validate routine to fire on the button click? I tried
Me.Validate(), but that always returned true...I guess I have to put my
final validations in the forms validate event?
It seems to me that form validation is much easier in ASP.Net apps.
JJ,
在我忘记之前,使用Ajax的原因之一是在网页上获得winforms
的行为。
Cor
" Cor Ligthert [MVP]" < no ************ @ planet.nlschreef in bericht
news:ep ************** @ TK2MSFTNGP04.phx .gbl ...
JJ,
Before I forget, one of the reasons to use Ajax is to get the winforms
behaviour on a webpage.
Cor
"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:ep**************@TK2MSFTNGP04.phx.gbl...
JJButer,
区别在于Winform的使用不同于
WebForm。一个webform就像一个经典的简单非智能工作站。
它发送所有数据,经过验证,如果错误,则发送消息
返回。
在winforms中检查每个控件的使用情况以及
验证是否完成,这使得对于用户来说,它在大多数情况下更加愉快
因为他们已经准备好了所有的盒子,并且通常没有错误也不会被抛出。可以有一些(商业)
规则,但这可能意味着这样做是因为只能检查数据上的全部视图
。
您可以在使用JavaScript的网页上模拟此行为,但绝不会像winform一样罚款。
我希望这个给出了一个想法,
Cor
< jj ****** @ hotmail.comschreef在bericht
news:11 ********************** @ m73g2000cwd.googlegr oups.com ...
JJButer,
The difference is that the use of a Winform is different than from a
WebForm. A webform behaves as a classic simple non intelligent
workstation.
It sends all data, that is validated and if it is wrong a message is send
back.
In winforms is the usage that every single control is checked and that the
validating is done on that, this makes it in most siutations more pleasant
for the users because as they have filled all the boxes they are ready and
normally no error cannot be throwed anymore. There can be some (business)
rules however that can mean that this is done because only the overal view
on the data can be checked.
You can simulate this behaviour on a webpage with JavaScript, but never as
fine as with a winform.
I hope that this gives an idea,
Cor
<jj******@hotmail.comschreef in bericht
news:11**********************@m73g2000cwd.googlegr oups.com...
>>我知道如何在我的winforms中使用ErrorProvider。我是吗?我验证了值并在验证事件中设置了ErrorProvider。如果没有
有效,我设置e.Cancel = True。我在
验证的事件中清除了ErrorProvider。
当用户点击OK按钮时,有没有办法知道所有经过验证的控件是否通过了验证?在ASP.Net中有Page.IsValid
方法。在winforms中是否有类似的东西,或者我是否还需要编写一个整体验证例程来点击按钮?我试过了.Validate(),但总是返回true ...我想我必须在表单验证事件中进行我的
最终验证吗?
它似乎在ASP.Net应用程序中,表单验证更容易。
>>I know how to use the ErrorProvider in my winforms..or do I? I validate
the values and set the ErrorProvider in the validating event. If not
valid, I set e.Cancel = True. I clear the ErrorProvider in the
validated event.
Is there a way to know if all validated controls pass validation when
the user clicks an OK button? In ASP.Net there''s the Page.IsValid
method. Is there something similar in winforms, or do I still have to
write an overall validate routine to fire on the button click? I tried
Me.Validate(), but that always returned true...I guess I have to put my
final validations in the forms validate event?
It seems to me that form validation is much easier in ASP.Net apps.
jj ****** @ hotmail.com 写道:
我知道如何在我的winforms中使用ErrorProvider。我是吗?我在值中验证了
并在验证事件中设置了ErrorProvider。如果没有
有效,我设置e.Cancel = True。我清除了
验证事件中的ErrorProvider。
有没有办法知道所有经验证的控件是否通过验证
用户单击确定按钮?在ASP.Net中有Page.IsValid
方法。在winforms中是否有类似的东西,或者我仍然需要
写一个整体验证例程以点击按钮点击?我试过了
Me.Validate(),但总是返回true ...我想我必须在表单validate事件中输入我的
最终验证?
在我看来,ASP.Net应用程序中的表单验证更容易。
I know how to use the ErrorProvider in my winforms..or do I? I validate
the values and set the ErrorProvider in the validating event. If not
valid, I set e.Cancel = True. I clear the ErrorProvider in the
validated event.
Is there a way to know if all validated controls pass validation when
the user clicks an OK button? In ASP.Net there''s the Page.IsValid
method. Is there something similar in winforms, or do I still have to
write an overall validate routine to fire on the button click? I tried
Me.Validate(), but that always returned true...I guess I have to put my
final validations in the forms validate event?
It seems to me that form validation is much easier in ASP.Net apps.
好吧,我没有做太多的WebForms,但是,在WinForms中,整个
验证的东西有点破碎。我绕过它的方式就像
这个,
private void textBox1_Validating(object sender,System.CancelEventArgs
e)
{
e.Cancel = ValidatePhoneNumber(testBox1.Text);
}
私人布尔ValidatePhoneNumber(字符串文本)
{
string message ="" ;;
if(... some test ...)
{
message ="电话号码无效。" ;;
}
errorProvider1.SetError(消息);
返回message.Length == 0;
}
然后,在OK按钮点击事件中:
private void okButton_Click(object sender,System.EventArgs e)
{
bool phoneNumberValid = ValidatePhoneNumber(textBox1.Text);
...
if(phoneNumberValid&& ...&& ...)
{
this.DialogResult = DialogResult.OK;
}
}
换句话说......好老滚动你自己的:写下你从验证中调用的单独例程
事件处理程序,然后在单击确定按钮时调用所有
。一个重要的诀窍是,你必须分别给每个人打电话,然后再评估布尔值
,或者使用非快捷方式&操作员而不是&&。
Well, I haven''t done much WebForms, but yes, in WinForms, the whole
validation thing is sort of broken. The way I got around it is like
this,
private void textBox1_Validating(object sender, System.CancelEventArgs
e)
{
e.Cancel = ValidatePhoneNumber(testBox1.Text);
}
private bool ValidatePhoneNumber(string text)
{
string message = "";
if (... some test ...)
{
message = "Phone number not valid.";
}
errorProvider1.SetError(message);
return message.Length == 0;
}
then, in the OK button click event:
private void okButton_Click(object sender, System.EventArgs e)
{
bool phoneNumberValid = ValidatePhoneNumber(textBox1.Text);
...
if (phoneNumberValid && ... && ... )
{
this.DialogResult = DialogResult.OK;
}
}
In other words... good old "roll your own": write separate routines
that you call from the "Validating" event handlers, then call all of
those when the OK button is clicked. The one important trick is that
you have to call each one separately, then evaluate the booleans
afterward, or use the non-shortcut & operator instead of &&.