468,556 Members | 2,135 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,556 developers. It's quick & easy.

RequiredFieldValidator failed?

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 em***@host.domain"
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
Nov 19 '05 #1
2 1916
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???
Hongbo wrote:
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 em***@host.domain"
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


Nov 19 '05 #2
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" <jo*********@topscene.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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???
Hongbo wrote:
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 em***@host.domain"
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

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by James | last post: by
5 posts views Thread by Fernando Lopes | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.