problem with customvalidator inside updatepanel

A

Anton

hi

asp.net 3.5

On my form I got a textbox and a linkbutton. I've associated a
requiredfieldvalidator and a customvalidator to the textbox.

The problem is that when I click on the linkbutton the ServerValidate_test
code is executed (that is normal), BUT then it executes the rest of the code
behind the linkbutton. So it looks like the linkbutton doesn't care of the
result from the customvalidator.....

customvalidator markup:
<asp:CustomValidator ID="valCustom" runat="server"
ValidationGroup="vg" ControlToValidate="txt1"
EnableClientScript="false"
OnServerValidate="ServerValidate_test"
ErrorMessage="Error message">*
</asp:CustomValidator>

ServerValidate_test code:
protected void ServerValidate_test(object sender, ServerValidateEventArgs e)
{
e.IsValid = false;
}

Linkbutton:
<asp:LinkButton ID="lb" runat="server" CausesValidation="true"
ValidationGroup="vg" OnClick="lb_Click">Save</asp:LinkButton>

I haven't specified <Triggers> in the updatepanel...

any suggestions?
 
M

miher

Anton said:
hi

asp.net 3.5

On my form I got a textbox and a linkbutton. I've associated a
requiredfieldvalidator and a customvalidator to the textbox.

The problem is that when I click on the linkbutton the ServerValidate_test
code is executed (that is normal), BUT then it executes the rest of the
code behind the linkbutton. So it looks like the linkbutton doesn't care
of the result from the customvalidator.....

customvalidator markup:
<asp:CustomValidator ID="valCustom" runat="server"
ValidationGroup="vg" ControlToValidate="txt1"
EnableClientScript="false"
OnServerValidate="ServerValidate_test"
ErrorMessage="Error message">*
</asp:CustomValidator>

ServerValidate_test code:
protected void ServerValidate_test(object sender, ServerValidateEventArgs
e)
{
e.IsValid = false;
}

Linkbutton:
<asp:LinkButton ID="lb" runat="server" CausesValidation="true"
ValidationGroup="vg" OnClick="lb_Click">Save</asp:LinkButton>

I haven't specified <Triggers> in the updatepanel...

any suggestions?


Hi,

As far i know this is working as intended, since the validation controls
won't stop event processing they just check the validity of the control they
assigned to. This can be a bit confusing since if client sripts are enabled
the validation javascript will not post the form if validation fails, but
when the validation run on server side (and it always should run on server
side too since client javascript can be hacked), it wont stop event
processing just sets Page.IsValid. You should check for that in Your button
event handler.
Please check http://msdn.microsoft.com/en-us/library/a0z2h4sw(VS.80).aspx
for example.

Hope You find this useful.
-Zsolt
 

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,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top