-1

I am creating a registration form using html, css & javascript for validation and it's working great if I put id="register-form" in form tag.

<form method="post" role="form" autocomplete="off" id="register-form">

IMG of validation https://i.stack.imgur.com/Oya5L.jpg

but as i also want <asp:Button ID="Button1" CssClass="btn-info" Text="Submit" />

To work this asp button I have to put runat="server" in form tag like this

<form method="post" role="form" id="register-form" onload="Page_Load" autocomplete="off" runat="server">

Then I got error in Visual Studio

'register-form' is not a valid identifier.

Edited Error is not displaying as before but validation still don't work I have used register_form

And if I remove id="register-form" from form tag validation not working.

IMG of not Working validation

http:// imgur.com/a/ QoHP5

Here my validation java script file

http:// pastebin.com/yGGu2dYR

My html/aspx file

http:// pastebin.com/i0ewCGrz

Update : It's not working if I change register-form to register_form in both html and java-script I run it without using runat

chackers
  • 25
  • 9
  • Look at the source code of the page in the browser ... what ID does the form element have – Jaromanda X Jan 21 '17 at 10:15
  • change the value `register-form` from form id like`register_form` and JS or wherever is used and it will work for sure – Pranav Patel Jan 21 '17 at 10:16
  • id="ctl00" in source code I don't understand what's that @JaromandaX – chackers Jan 21 '17 at 10:19
  • did'nt display any error like before but validation still didn't work ..! @PranavPatel – chackers Jan 21 '17 at 10:21
  • I'm surprised it's only ctl00 ... usually ASP mangles ID's together with the original ID in your code - maybe it's the '-' in the original ID that stops it from using the original. Anyway, it's an ASP thing ... I believe there's a way to prevent it, some configuration or other – Jaromanda X Jan 21 '17 at 10:21
  • Only combinations of alphanumeric characters and the underscore character ( _ ) are valid values for this property. Including spaces or other invalid characters will cause an ASP.NET page parser error. Check http://msdn.microsoft.com/en-us/library/system.web.ui.control.id.aspx – Pranav Patel Jan 21 '17 at 10:23
  • see [this SO question](http://stackoverflow.com/questions/497802/how-to-stop-asp-net-from-changing-ids-in-order-to-use-jquery) for possible solutions – Jaromanda X Jan 21 '17 at 10:24
  • You need to decide if you want your form to be server side or not (`runat`). If not, then dump the server control ` – EdSF Jan 21 '17 at 17:28

1 Answers1

0

You need to change code like bellow to validation to work:

Html change and add class to form

<form method="post" role="form" class="register_form" id="register_form" onload="Page_Load" autocomplete="off" runat="server">

And In validation javascript file Change from id selection

$("#register-form")

To class selection

$(".register_form")

After these step your validation will work fine with form with runat="server"

Ravi Patil
  • 127
  • 2
  • 16
Bharatsing Parmar
  • 2,435
  • 1
  • 9
  • 18
  • Not error but displaying in message box **Validation (XHTML5): Attribute 'clientidmode' is not a valid attribute of element 'form'** & validation didn't work – chackers Jan 21 '17 at 10:32
  • In this case need to add class in form and validate accordingly. You can check updated answer. – Bharatsing Parmar Jan 21 '17 at 10:36