我的验证 asp.net 应用程序中的错误是什么
本文关键字:错误 是什么 应用程序 验证 asp net 我的 | 更新日期: 2023-09-27 18:37:19
net application.使用此应用程序,用户可以添加一段时间的来宾连接。为此,我有一个按钮,可以打开一个模式对话框,用户可以添加来宾。输入必须是名字,姓氏,公司和时间。我使用验证控件和验证组。验证控件检查我是否忘记了输入,但如果我单击"添加",代码不会运行。我尝试使用简单的div但相同的方法:
这是我的aspx代码:
<div id="add">
<div id="Div2" class="popupConfirmation" runat="server" style="width:350px; height:290px;">
<div class="bodycontrol">
<table>
<tr>
<td><asp:Label ID="Label3" runat="server" Text="Vorname"></asp:Label></td>
<td><asp:TextBox ID="TextBox1" runat="server" ValidationGroup="valid" ></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="valid" runat="server" ForeColor="red" ErrorMessage="*" ControlToValidate="TextBox1"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td><asp:Label ID="Label4" runat="server" Text="Nachname"></asp:Label></td>
<td><asp:TextBox ID="TextBox2" runat="server" ValidationGroup="valid"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="valid" runat="server" ForeColor="red" ErrorMessage="*" ControlToValidate="TextBox2"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td><asp:Label ID="Label5" runat="server" Text="Firma"></asp:Label></td>
<td><asp:TextBox ID="TextBox3" runat="server" ValidationGroup="valid"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator3" ValidationGroup="valid" runat="server" ForeColor="red" ErrorMessage="*" ControlToValidate="TextBox3"></asp:RequiredFieldValidator></td>
</tr>
</table>
<br />
<table>
<tr>
<td><asp:LinkButton ID="LinkButton1" runat="server" class="GuestButtons" Text="Hinzufügen" ValidationGroup="valid" onclick="btn_GuestListViewAddDialog_YES_Click" ></asp:LinkButton></td>
<td><asp:LinkButton ID="LinkButton2" runat="server" class="GuestButtons" Text="Abbrechen" ValidationGroup="never"></asp:LinkButton></td>
</tr>
</table>
<br />
<table>
<tr>
<td><asp:Label ID="Label10" runat="server" Text="*Bitte alle Felder ausfüllen"></asp:Label></td>
</tr>
</table>
</div>
</div>
</div>
这是我的 C# 代码:
protected void btn_GuestListViewAddDialog_YES_Click(object sender, EventArgs e)
{
if (Page.IsValid) //Here i make a breakpoit but it doesn't use this code :(
{
...//here is my code
}
}
如果我单击链接按钮,这在我的脚本块中:
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$lw_content$LinkButton1", "", true, "valid", "", false, true))
如果要在服务器端强制验证,则需要在检查Page.IsValid
之前调用Page.Validate()
。
protected void btn_GuestListViewAddDialog_YES_Click(object sender, EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
LinkButton
还必须具有ValidationGroup
、如果要在单击链接按钮时验证此组,则为同一valid
组;如果不想触发验证,则为其他组。
编辑:但是,Page.Validate
应该是多余的,因为默认情况下CausesValidation
LinkButton
true
,并且您还为其指定了ValidationGroup
。所以我不知所措。