Update ValidationSummary list on control blurs?

后端 未结 1 1303
终归单人心
终归单人心 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 <asp:TextBox> tags will still work: <system.web> <pages> <tagMapping> <add tagType="System.Web.UI.WebControls.TextBox" mappedTagType="MyControls.TextBoxEx"/> </tagMapping> </pages> </system.web>

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

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

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