2

您能否解释一下为什么在 asp.net 上的 sql server 中插入空值并提供验证(例如:必填字段验证器)?
虽然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>
4

2 回答 2

0

在您的服务器端代码中使用Page.IsValid来验证您的客户端验证是否有效,也可以尝试对空格使用正则表达式验证器。如果您可以在存储过程中添加一个空条目检查会更好。

于 2013-09-02T07:28:51.163 回答
0

尝试将此添加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,这是默认行为,所以无论它会提交您的表单,尝试使用return false;on OnClick。它将停止表单执行其默认行为。我对此知之甚少,telerik所以我只是根据我所知道的建议,希望它对你有用。:-)

于 2013-09-02T09:01:12.610 回答