user2053590
user2053590

Reputation: 57

Issue in password field validation asp.net C#

I have to make validation for password. It works fine but if i add runat=server my password validation does not work.And when i remove runat server it works fine.

my code is as:

<input value=""  runat="server" class="validate[required] text-input" type="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" name="password" id="password" />


    <input value="" runat="server"  class="validate[required,equals[password]] text-input" type="password" name="password2" id="password2" />

Any help on this topic will be appreciated.

Upvotes: 0

Views: 788

Answers (2)

Anant Dabhi
Anant Dabhi

Reputation: 11104

when you put space in control properties asp create diffrent properties for element in your textbox control you are creating properties like required pattern So, ASP Create your text box html like this

<input name="password" type="password" id="password" required="" pattern="asdsa" class="validate[required] text-input" />

Answer

So you need to create properties using code behind

you can Add control attribute at code behind if you having problem in ASP page

<input value=""  runat="server" class="validate[required] text-input" type="password" name="password" id="password" />

at code behind

 protected void Page_Load(object sender, EventArgs e)
{
    password.Attributes.Add("required pattern","(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,}");

}

Upvotes: 0

shankar.parshimoni
shankar.parshimoni

Reputation: 1299

You have taken normal HTML tag telling to act as server side control i,e runat="Server".Normal html control will not work as server side control,So please take asp.net controls and write required code.

<asp:TextBox runat="server"/>

Upvotes: 2

Related Questions