validation summary problem

£可爱£侵袭症+ 提交于 2020-01-14 11:02:17

问题


i have a page where i am using validation 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


回答1:


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.




回答2:


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




回答3:


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>
<% } %>


来源:https://stackoverflow.com/questions/2182205/validation-summary-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!