Newbie Question - Master Page triggering validator

D

damiensawyer

Hello all,

I have set up a very simple master page (a table, a button and a
ContentPlaceHolder) and have set a simple web form to use it.

The web form (code below) has a textbox, a simple validator and a
button on it. When I press the button on the 'sub' form, I wish for
validation to take place and redirection as appropriate.

The problem is that, when the button on the master form is pressed, it
too triggers validation. I am guessing that it is not doing it via my
button press code, however just as the default behaviour of the
validator.

Can someone please tell me what I'm doing wrong?

Thanks very much in advance,


Damien Sawyer



<%@ Page trace="true" Language="VB"
MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
'Me.Validate()
If Me.IsValid Then Me.Response.Redirect("~/SQL.aspx")

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Trace.Write("Hello from Trace")
End Sub


</script>

<asp:Content ID="Content1"
ContentPlaceHolderID="bodyContentPlaceHolder" Runat="Server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Login" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1"
ErrorMessage="Name Required" ></asp:RequiredFieldValidator>
</asp:Content>
 
D

Daniel TIZON

Hi Damien,
If you don't whant a button to participate to the page validation, you can
set his "CauseValidation" property to false.
Another solution, now available with ASP.NET2.0 is to isolate validators and
buttons by groups.
For an example, you can set the property "ValidationGroup" of the button and
validators of your content page to "group1", so your button will only verify
the validtity on the validators in the same ValidationGroup

Hope this helps,
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top