RequiredFieldValidator failed?

H

Hongbo

Hi,

I have a Asp.Net written in C#. It serve as information input form. The form encounters sort of
random problem with the email field and state field. I have validator attached with these 2 fields
as the following:
=====
<form id="creditcardform" method="post" runat="server">
Email: <asp:textbox id="txtBillEmail" maxlength="50" width="200" runat="server" />
<asp:requiredfieldvalidator id="vp10" runat="server" initialvalue=""
controltovalidate="txtBillEmail" errormessage="Billing Email cannot be empty" />
<asp:regularexpressionvalidator id="vp11" runat="server" controltovalidate="txtBillEmail"
errormessage="Billing Email must follow (e-mail address removed)"
validationexpression="^.+\@.+\..+$" display="Dynamic" />

State: <asp:dropdownlist id="lstBillState" runat="server" />
<asp:requiredfieldvalidator id="vp7" runat="server" initialvalue=""
controltovalidate="lstBillState"
errormessage="Billing State must select one" display="Dynamic" />

<asp:button id="btnSubmit" causesvalidation="True" text="Submit" runat="server" cssclass="button" />
</form>
=====

My understanding is that the <asp:requiredfieldvalidator> should guarantee the value of the field when the value of
"causesvalidation" sets to "True" in the submit button. But what happened was that no error was generated when "btnSubmit" was clicked, but the value of one of these 2 fields get lost in the codebehind file. I tried to catch it on our development server, but I've never caught it. It only occurs on our production server. This problem doesn't always occur.
It only happens once a while randomly.

Would you please help me to figure out the cause of such value loss?

Thank you

hb
 
J

Joey

Both the regular expression and custom validators do not perform
client-side or server-side validation when no value is entered into the
control that is set for the validators' "ControlToValidate" properties.
This is by design.

Maybe that's what is causing it???
 
H

Hongbo

Hi, Joey,

Thank you for helping me.

I have ASP:RequiredFieldValidator attached with both TextBox and
DropdownList.
My understanding is that ASP:RequiredFieldValidator should prevent the
submit
button click to go any further if either of the controls contains no value.

But the fact was that the button click event did fire without error. What I
guess is that
the user might input value in these 2 controls and that the value get lost
somehow
when the button click event tried to retrieve value from these control in
CodeBehind.

But how could that happen?
Joey said:
Both the regular expression and custom validators do not perform
client-side or server-side validation when no value is entered into the
control that is set for the validators' "ControlToValidate" properties.
This is by design.

Maybe that's what is causing it???
happened was that no error was generated when "btnSubmit" was clicked, but
the value of one of these 2 fields get lost in the codebehind file. I tried
to catch it on our development server, but I've never caught it. It only
occurs on our production server. This problem doesn't always occur.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top