|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie Question - Master Page triggering validatorI 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> 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, -- Show quoteDaniel TIZON MCP - MCSD.NET - MCT <damiensaw***@yahoo.com.au> a écrit dans le message de news: 1134801351.246642.315***@g43g2000cwa.googlegroups.com... > 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> > |
|||||||||||||||||||||||