RequiredFieldValidator disable on new page load

B

bdtmike

I'm using VS2005. I have a form that has fields and a required field
validator control on it. Everything works great except there's a
behavior I'm trying to get working. If a user is on a form and are in
the middle of editing it, they can click other links on the page that
would take them elsewhere and out of the form edit. Problem is that
the validator fires off that required fields are not completed and
prevents the new page from being loaded. Any idea how I can turn this
validator off when it detects that a new page is being loaded?
 
N

Nathan Sokalski

Set the CausesValidation property of the Button, ImageButton, or LinkButton.
If the Control they are clicking is not one of these Control types, let us
know what type it is so we can help more. Good Luck!
 
K

Ken Cox - Microsoft MVP

Hi Mike,

I'm not sure I understand your problem, but is it that the user can't
navigate away because of the validation? If so, set causesvalidation="False"
for any control that allows the user to leave. I've pasted in a small sample
below.

If I missed your real issue, let us know?

Ken
Microsoft MVP [ASP.NET]


<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

End Sub

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.Redirect("http://www.kencox.ca")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:textbox id="TextBox1" runat="server"></asp:textbox>
<asp:requiredfieldvalidator id="RequiredFieldValidator1"
runat="server" controltovalidate="TextBox1"
errormessage="Required!"></asp:requiredfieldvalidator><br />
<br />
<asp:button id="Button1" runat="server" onclick="Button1_Click"
text="Button" />
<br />
<br />
<asp:linkbutton id="LinkButton1" runat="server"
causesvalidation="False"
onclick="LinkButton1_Click">LinkButton</asp:linkbutton>

</div>
</form>
</body>
</html>
 
N

Nathan Sokalski

Do you, anywhere in your code, call the Validate() method (of either the
Page object or a specific Validator)? I think it might help us if we could
see all your code, sometimes it can be hard to find the problem when we have
to try to think of every possible scenario. (NOTE: It is a good idea to
include the previous messages in your replies so that people responding can
see what you have already tried, what others have suggested, etc. without
needing to open every message).
 
B

bdtmike

Well, the "causes validation" isn't an option when the user clicks on a
hyperlink on the page. This is a regular old hyperlink and there's no
property to set for this that would turn off validation.
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top