Update ValidationSummary list on control blurs?

后端 未结 1 1424
终归单人心
终归单人心 2020-12-20 05:27

A ValidationSummary will show a list of errors on postback. As each field is fixed, it\'s validator is fired, and any validation text will disappear. I want to

1条回答
  •  忘掉有多难
    2020-12-20 06:32

    Here's a server-side approach to get the onblur attribute on all TextBoxes (which should also work with Validation Groups):

    • Create a class derived from TextBox, e.g., TextBoxEx
    • Add the attribute in this derived class e.g., this.Attributes.Add("onblur", string.Format("ValidationSummaryOnSubmit('{0}')", this.ValidationGroup);
    • Use tag mapping so that all of your existing tags will still work:

    Another way would be to use ControlAdapters to add the attribute.

    Relevant links:
    Understanding ASP.NET Validation
    MSDN - tagMapping Element for pages

    0 讨论(0)
提交回复
热议问题