开发者

validation summary problem

开发者 https://www.devze.com 2022-12-19 09:18 出处:网络
i have a page where i am using vali开发者_如何学运维dation summary and required field validators. When i click the validation button error message is being dispalyed in both validation summary is show

i have a page where i am using vali开发者_如何学运维dation summary and required field validators. When i click the validation button error message is being dispalyed in both validation summary is showing message written in required field validators. I want to display different message in validation summary and required field validators. e.g validation summary should display "field marked with * are mandatory" and required field validator should display only a "*".

Thanks


Set your validator's Text property to "*". This will be displayed at validator's text when validation fails, and the ErrorMessage will be displayed by the validation summary.


Pankaj try this code...

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ErrorMessage="Error" ControlToValidate="TextBox1">*</asp:RequiredFieldValidator>

    <br />
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
        DisplayMode="List" />
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />

Here i have set the DisplayMode property of validation summary to List


For anyone else looking up how to do this - like I just was - this works for me using MVC4:

Model:

 [Required(ErrorMessage="*")]
 public string Name { get; set; }

CSS:

.validation-summary-errors ul
{
    display: none;
}

View Form:

<% using (Html.BeginForm("Send", "Contact") ){ %> <%--<%: Html.ValidationSummary(false, "Fields marked * required", new { @style = "display:none"})%>--%> <%: Html.ValidationSummary(false, "Fields marked * required")%>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.Name) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.Name) %>
            <%: Html.ValidationMessageFor(model => model.Name) %>
        </div>
        <p>
            <input type="submit" value="Send" />
        </p>
    </fieldset>
<% } %>
0

精彩评论

暂无评论...
验证码 换一张
取 消