在asp.net上的sql server中插入空值,并提供了所需的字段验证器
本文关键字:验证 字段 上的 net asp sql server 空值 插入 | 更新日期: 2023-09-27 18:29:48
你能解释一下为什么在asp.net上的sql服务器中插入空值吗是否提供了验证(例如:必填字段验证程序)
尽管sql表列类型是varchar,但在存储过程中,参数也定义为varchar,而不是null。但对于某些记录,这些字段被插入为空值(非"NULL")
添加自下方评论
<telerik:RadTextBox ID="txtFirstName" runat="server" MaxLength="23"
EnableSingleInputRendering="False"
CssClass="signuptxt">
<EnabledStyle Width="250px" />
</telerik:RadTextBox>
<asp:RequiredFieldValidator ID="rfvFirstName" runat="server"
ControlToValidate="txtFirstName"
ErrorMessage="First Name is required"
ToolTip="First Name is required"
ForeColor="Red"
ValidationGroup="regcust">*
</asp:RequiredFieldValidator>
<telerik:RadButton ID="btnRegister" class="submit" type="submit" runat="server" Text="Register Customer" Width="210px" Font-Size="Large"
Skin="buttonRed" EnableEmbeddedSkins="false" ValidationGroup="regcust" OnClick="btnRegister_Click">
</telerik:RadButton>
在服务器端代码中使用Page.IsValid
来验证客户端验证是否有效。也可以尝试对空格使用正则表达式验证器。如果可以在存储过程中添加一个空条目检查,那会更好。
尝试将此causesvalidation="true"
添加到按钮中。
<telerik:RadButton ID="btnRegister" class="submit" type="submit" causesvalidation="true" runat="server" Text="Register Customer" Width="210px" Font-Size="Large"
Skin="buttonRed" EnableEmbeddedSkins="false" ValidationGroup="regcust" OnClick="btnRegister_Click">
</telerik:RadButton>
提交按钮将始终提交form
,这是默认行为,因此无论它将提交什么表单,请尝试在OnClick
上使用return false;
。它将停止窗体以执行其默认行为。我对telerik
一无所知,所以我只是在我所知道的基础上提出建议,希望它对你有用。:-)