Andreas Thente
Andreas Thente

Reputation: 23

ValidationGroup doesn´t validate on a button in HTML5

My following code renders an invalid attribute in HTML, ValidationGroup, on a button.

aspx-file:

<button runat="server" id="btnSubmit" onserverclick="btnSubmit_Click" causesvalidation="true" class="button floatRight">

cs-file:

btnSubmit.ValidationGroup = UniqueID;

This renders:

<button validationgroup="ctl00$NoBody$FullContent$ctl03$ctl01" class="button floatRight" id="ctl00_NoBody_FullContent_ctl03_ctl01_btnSubmit" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate('ctl00$NoBody$FullContent$ctl03$ctl01'); __doPostBack('ctl00$NoBody$FullContent$ctl03$ctl01$btnSubmit','')"><span class="left"><!-- left --></span>Subscribe<span class="right"><!-- right --></span></button>

My problem is that ValidationGroup makes the code invalid in HTML5 and I don´t know how to get around this. It seems like the attribute is only rendered on Button, other elements like Inputs doesn´t render this attribute although it has the same ValidationGroup.

Has someone got around this? Thanks.

Upvotes: 1

Views: 1429

Answers (1)

Give your button a name attribute as well as the ID. Works for me and I was having the exact same issue. I then went back 10 years and remembered the good old Name tag.

Upvotes: 1

Related Questions