Get Passwords do not Match message too soon

  • Thread starter Thread starter AAaron123
  • Start date Start date
A

AAaron123

I have a textbox for password and one for passwordconfirm with no attributes
except ID, TextMode, Runat.
Also have:

<asp:Button ID="ButtonSetUserPassword" runat="server" Width="150px"
Text="Set Password"

ValidationGroup="adminsetpassword" />



<asp:CompareValidator ID="CompareValidatorPassword" runat="server"
ControlToValidate="TextBoxNewPassword"

ControlToCompare="TextBoxPasswordConfirm" Type="string" Operator="equal"

ErrorMessage=" * the password and confirm password fields do not match."
Display="Dynamic"

ValidationGroup="adminsetpassword" />

As soon as I leave the first textbox I get the do not match message.

It really should not check until after the second box is filled but I din't
know how to make that happem.



Thanks
 
Mark Rae said:
1) Don't use Validators - use client-side JavaScript:

<script type="text/javascript">
function validateForm()
{
var txtNewPassword =
document.getElementById('<%=TextBoxNewPassword.ClientID%>');
var txtConfirmPassword =
document.getElementById('<%=TextBoxPasswordConfirm.ClientID%>');

if (txtConfirmPassword.value != txtNewPassword.value)
{
alert(' * the password and confirm password fields do not
match.');
txtConfirmPassword.focus();
return false;
}
}
</script>


2) Do the validation behind the Button.

<asp:Button ID="ButtonSetUserPassword" runat="server" Width="150px"
Text="Set Password" OnClientClick="return validateForm();" />

That works nicely. User could not miss the alert box!

However I thought one reason for the validators is that they check both
client side and server side to prevent the user from mucking on the client
side.

BTW. In that same example I noticed, as shown at the bottom, the element
split.

Help defines it as <asp:Label />
Is it always allowed to convert elements to <asp:Label></asp:Label>?
And what does it mean to insert the textbox?
How is it different from having the textbox follow?

<asp:Label ID="LabelNewPassword" runat="server"
AssociatedControlID="TextBoxNewPassword">

New Password<br />

<asp:TextBox ID="TextBoxNewPassword" Width="300px" TextMode="password"

runat="server" /><br />

</asp:Label>


As always, thanks a lot!
 
Mark Rae said:
Indeed. And, now that you know how to roll your own validation properly,
hopefully you'll abandon the Validation webcontrols completely...

I didn't expect that!
Is it your impression that many seasoned developer fell that way?
What does that mean...?

You can validate client-side or server-side.
Disadvantage of client-side (I think) is that a user could change the page
so that it submits with things that would have not validtaed - so the
validators check both client and server sides. Yes, no?


I don't think those sites relate to my question. I wasn't wondering about
self-closing a tag that is normally not self-closed, but rather the
opposite, ASP.Label is defined as <asp:Label /> so I was surprised to see it
used as <asp:Label>Textbox</asp:Label> but when I look at the LABEL Element
| label Object documentation I find an example of the label element split.

But that documentation does not give the element syntax. I suspect there is
some general rules that it assumes and the docs does not repeat it.

Also, when try to track it down by looking at the HTML source delivered to
the browser I find an asp.label might convert into a span element rather
than a label element.

So it's all confusing, but not knowing does not stop me from developing.

However, it would be nice to know the difference between
<asp:Label runat="server" Text="JUNK"><asp:TextBox ID="TextBox0"
runat="server" /></asp:Label>

<asp:Label runat="server" Text="JUNK" /><asp:TextBox ID="TextBox1"
runat="server" />

<asp:Label runat="server" Text="JUNK"></asp:Label><asp:TextBox ID="TextBox2"
runat="server" />

which produces
<span>JUNK<input name="TextBox0" type="text" id="TextBox0" /></span>
<span>JUNK</span><input name="TextBox1" type="text" id="TextBox1" />
<span>JUNK</span><input name="TextBox2" type="text" id="TextBox2" />

One case the input element is in the scan and the others it is outside. Make
any difference?

And there is still my old question:

Can I take any asp self-closing server control and split it?

If so what is the effect.



Thanks again
 
Back
Top