gpt4 book ai didi

asp.net - Asp.net和Ext.Net验证

转载 作者:行者123 更新时间:2023-12-02 04:06:39 24 4
gpt4 key购买 nike

有人给我展示ext.net验证的示例吗?我想混合使用asp.net和ext.net验证。或仅使用ext.net验证。

我已经看过这些示例http://examples.ext.net/#/Form/Validation/Custom_VType/http://examples.ext.net/#/Form/FormPanel/Validation/,但这还不够。

另外,我想知道为什么代码底部不起作用。引发异常

“Page.IsValid无法在验证之前调用。它
应该在事件处理程序中查询具有
CausesValidation = True并启动了回发,或者在
Page.Validate”

<script runat="server">

void Button_Click(object sender, EventArgs e) {
// Display whether the page passed validation.
if (Page.IsValid) {
Label1.Text = "Page is valid.";
}
else {
Label1.Text = "Page is not valid!";
}
}

void ServerValidation(object source, ServerValidateEventArgs args) {
try {
// Test whether the value entered into the text box is even.
int i = int.Parse(args.Value);
args.IsValid = ((i % 2) == 0);
}
catch (Exception ex) {
args.IsValid = false;
}
}

</script>
<ext:Label ID="Label1" runat="server" Text="Enter an even number:" />
<br />
<ext:TextField ID="TextField1" runat="server" />
<asp:CustomValidator runat="server" ControlToValidate="TextField1" OnServerValidate="ServerValidation"
ErrorMessage="Not an even number!" />
<ext:Button runat="server" Text="Validate" >
<DirectEvents>
<Click OnEvent="Button_Click" />
</DirectEvents>
</ext:Button>

最佳答案

这个样本怎么样?在pastebin中:http://pastebin.com/hGCjnNqh

<script runat="server">
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);

Page.Validate();

}

void ServerValidation(object source, ServerValidateEventArgs args)
{
try
{
// Test whether the value entered into the text box is even.
int i = int.Parse(args.Value);
args.IsValid = ((i % 2) == 0);
}
catch (Exception ex)
{
args.IsValid = false;
}
}

void Button_Click(object sender, EventArgs e) {
// Display whether the page passed validation.
if (Page.IsValid) {
Label1.Text = "Page is valid.";
} else {
Label1.Text = "Page is not valid!";
}
}
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Label ID="Label1" runat="server" Text="Enter an even number:" />
<br/>
<ext:TextField ID="TextField1" runat="server" />
<asp:CustomValidator ID="CustomValidator1"
runat="server"
ControlToValidate="TextField1"
OnServerValidate="ServerValidation"
ErrorMessage="Not an even number!" />
<ext:Button ID="Button1" runat="server" Text="Validate" AutoPostBack="false" CausesValidation="true">
<DirectEvents>
<Click OnEvent="Button_Click" />
</DirectEvents>
</ext:Button>

关于asp.net - Asp.net和Ext.Net验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7266740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com