i have a signup page that runs with a masterpage and the page worked fine before i started adding validation controls and then it just stopped working .. i;m including both the content and code-behind pages. the Submit and clear buttons stopped working
i added the group to all validators and the submit button but i still have the same issue.. i added ValidationGroup="signupValGroup" to them all but still the same thing
Dude u cant be adding same validation control to all the controls.Just add validation group to the particular validation controls that u want to invoke on Submit button.
Don't have both buttons call the same exact button click event handler. You can have each one call it's own handler. There is absolutely no reason to have one button handler and try to then determine which button caused the event.
If you ensure that your submit button, and all the validators use the exact same ValidationGroup then you should be ok. On the submit though, you also need to do an if Page.IsValid check to ensure that the validators are saying that everything is correct.
Don't forget to mark useful responses as Answer if they helped you towards a solution.
i tried both way and slit up the button click events and the clear works fine but the submit wont add the record into the database like it used to. before i had that IfPage,IsValid right under the SubButtonClick event and if it was the clear button it ran
through the first code Else it ran the submit code and records were added into the database .. then i added the validators and both buttons stopped responding and now i have the clear button working but my submit wont add record to database and i'm not sure
why or how this happened
Thanks, but i read up on validator controls and fixed it and meant to come back and post. Can you help me with master pages or point to a good resource. I have a root directory where i want the to keep and use the masterpage like a company"Header" but then
have subfolders with diiferent aspx apps using the masterpage from above.
Da69Devil
Member
2 Points
17 Posts
Validation messed my submit function
Apr 21, 2012 05:20 AM|LINK
i have a signup page that runs with a masterpage and the page worked fine before i started adding validation controls and then it just stopped working .. i;m including both the content and code-behind pages. the Submit and clear buttons stopped working
Content Page
<%@ Page Language="VB" MasterPageFile="~/InfoSiteMasterPage.master" AutoEventWireup="false" CodeFile="signup.aspx.vb" Inherits="Signup" %> <asp:Content runat="server" ID="SignupHeaderDefault" ContentPlaceHolderId="CPHHeaderTitleLeft"> <asp:Label runat="server" ID="TopLeftHeaderText" Text= "Please fill in the form completely" /> </asp:Content> <asp:Content ID="Content1" runat="server" contentplaceholderid="CPHHead"> <title>O.C.D.I.A. One Call Does It All</title> </asp:Content> <asp:Content runat="server" ID="MainContent" ContentPlaceHolderId="CPHdbContent"> <div style="margin: 0px auto; width:700px" class="divcenter">Please complete the form and click the submit button. You will need to await an email with your temporary password from us before you can log in and enjoy our Member Services </div> <table class="center" width="800px" cellpadding="0" cellspacing="0" > <tr> <td width="180px"> </td> <td width="5px"> </td> <td align="left" style="width:600px"> </td> </tr> <tr> <td></td> <td></td> <td align="left"> <asp:Label id="lblOutput" runat="server" Enabled ="false" /> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblFName" runat="server" Font-Bold="true" Text= "First Name" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtFname" runat="server" BackColor="#CCAAEE"></asp:TextBox> <asp:RequiredFieldValidator id="FnameRequiredFieldValidator" runat="server" ForeColor="Purple" ControlToValidate="txtFname" CssClass="universalbutton" SetFocusOnError="True" ErrorMessage=" *You need to enter your First name! " > </asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblLName" runat="server" Font-Bold="true" Text= "Last Name" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtLname" runat="server" BackColor="#CCAAEE"></asp:TextBox> <asp:RequiredFieldValidator id="LnameRequiredFieldValidator" runat="server" ForeColor="Purple" ControlToValidate="txtLname" CssClass="universalbutton" SetFocusOnError="True" >   *You will need to enter your Last name!   </asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblUnit" runat="server" Font-Bold="true" Text= "Unit #" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtUnit" runat="server" BackColor="#CCAAEE"></asp:TextBox> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblStNum" runat="server" Font-Bold="true" Text= "Street #" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtStNumb" runat="server" BackColor="#CCAAEE"></asp:TextBox> <asp:RangeValidator runat="server" ID="StNumRangeValidator" ControlToValidate="txtStNumb" Type="Integer" MinimumValue="1" MaximumValue="99999" SetFocusOnError="True" CssClass="universalbutton" Display="Dynamic" ErrorMessage="Please only use numbers from 0-9" > </asp:RangeValidator> <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ForeColor="Purple" CssClass="universalbutton" ControlToValidate="txtStNumb" SetFocusOnError="True" ErrorMessage=" *You need to enter your address! "> </asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblStName" runat="server" Font-Bold="true" Text= "Street Name" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtStName" runat="server" BackColor="#CCAAEE"></asp:TextBox> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblStType" runat="server" Font-Bold="true" Text= "Street Type" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtStType" runat="server" BackColor="#CCAAEE"></asp:TextBox> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblCity" runat="server" Font-Bold="true" Text= "City" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtCity" runat="server" BackColor="#CCAAEE"></asp:TextBox> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblProv" runat="server" Font-Bold="true" Text="Province" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtProv" runat="server" BackColor="#CCAAEE">Ontario</asp:TextBox> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblCountry" runat="server" Font-Bold="true" Text= "Country" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtCountry" runat="server" BackColor="#CCAAEE" Text="Canada">Canada</asp:TextBox> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblPostal" runat="server" Font-Bold="true" Text= "Postal Code" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtPostal" runat="server" BackColor="#CCAAEE"></asp:TextBox> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblHomePh" runat="server" Font-Bold="true" Text= "Home Phone #" Enabled="true"></asp:Label> </td> <td></td> <td align="left" > <asp:TextBox ID="txtHomePh" runat="server" BackColor="#CCAAEE">905-</asp:TextBox> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblCell" runat="server" Font-Bold="true" Text="Cell Phone #" Enabled="true" ></asp:Label> </td> <td></td> <td align="left" > <asp:TextBox ID="txtCell" runat="server" BackColor="#CCAAEE">905-</asp:TextBox> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblEmail" runat="server" Font-Bold="true" Text= "Email" Enabled="true"></asp:Label> </td> <td></td> <td align="left" > <asp:TextBox ID="txtEmail" runat="server" BackColor="#CCAAEE"></asp:TextBox> <asp:RegularExpressionValidator ID="EmailValidator" runat="server" ControlToValidate="txtEmail"> </asp:RegularExpressionValidator> <asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ForeColor="Purple" CssClass="universalbutton" ControlToValidate="txtEmail" SetFocusOnError="True" ErrorMessage=" *You need to enter a valid email address! " > </asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="lblComment" runat="server" Font-Bold="true" Text= "Comments" Enabled="true"></asp:Label> </td> <td></td> <td align="left"> <asp:TextBox ID="txtComment" runat="server" BackColor="#CCAAEE" Height="90px" TextMode="MultiLine" Width="320px"></asp:TextBox> </td> </tr> <tr> <td colspan="3"></td> </tr> <tr> <td></td> <td></td> <td align="left" > <asp:Button ID="SubmitButton" runat="server" CssClass="widerButtonStyle" Text="Submit" onclick="SubClear_Button_Click" /> <asp:Button ID="ClearButton" onclick="SubClear_Button_Click" CausesValidation="false" runat="server" Text="Clear" CssClass="widerButtonStyle" /> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> </table> </asp:Content>code-behind page
Imports System.Data.SqlClient Imports System.Web.Configuration Imports System.Data Public Class Signup Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If IsPostBack Then lblOutput.Enabled = True lblOutput.Text = "* All fields have been cleared" Else lblOutput.Enabled = False lblOutput.Text = "" End If End Sub Protected Sub SubClear_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click If sender.ID = "ClearButton" Then txtFname.Text = "" txtLname.Text = "" txtUnit.Text = "" txtStNumb.Text = "0" txtStName.Text = "" txtStType.Text = "" txtCity.Text = "" txtProv.Text = "Ontario" txtCountry.Text = "Canada" txtPostal.Text = "" txtHomePh.Text = "905-" txtCell.Text = "" txtEmail.Text = "" txtComment.Text = "" lblOutput.Enabled = True lblOutput.Text = "* All fields have been cleared" End If If sender.ID = "SubmitButton" Then Dim strSQLQuery As String Dim objConnection As SqlConnection Dim objCommand As SqlCommand objConnection = New SqlConnection(WebConfigurationManager.ConnectionStrings("ocdiaCustSignupConnectionString").ToString()) ' Our insert command strSQLQuery = "INSERT INTO user_signup " _ & "(firstname, lastname, unitnumber, streetnumber, " _ & "streetname, streettype, city, province, country, postal, " _ & "homephone, cellphone, comments, email ) " _ & "VALUES (@fName, @lName, @unit, " _ & "@stnumb, @stname, @sttype, @city1, @prov1, @count1, @Postal, " _ & "@home, @cell, @comment, @email )" ' Create new command object passing it our SQL insert ' and telling it which connection to use. objCommand = New SqlCommand(strSQLQuery, objConnection) ' Add parameters that our SQL command takes: objCommand.Parameters.Add(New SqlParameter("@fName", SqlDbType.VarChar, 50)) objCommand.Parameters.Add(New SqlParameter("@lName", SqlDbType.VarChar, 50)) objCommand.Parameters.Add(New SqlParameter("@unit", SqlDbType.VarChar, 15)) objCommand.Parameters.Add(New SqlParameter("@stnumb", SqlDbType.VarChar, 6)) objCommand.Parameters.Add(New SqlParameter("@stname", SqlDbType.VarChar, 6)) objCommand.Parameters.Add(New SqlParameter("@sttype", SqlDbType.VarChar, 20)) objCommand.Parameters.Add(New SqlParameter("@city1", SqlDbType.VarChar, 30)) objCommand.Parameters.Add(New SqlParameter("@prov1", SqlDbType.VarChar, 30)) objCommand.Parameters.Add(New SqlParameter("@count1", SqlDbType.VarChar, 20)) objCommand.Parameters.Add(New SqlParameter("@Postal", SqlDbType.VarChar, 9)) objCommand.Parameters.Add(New SqlParameter("@home", SqlDbType.VarChar, 20)) objCommand.Parameters.Add(New SqlParameter("@cell", SqlDbType.VarChar, 20)) objCommand.Parameters.Add(New SqlParameter("@comment", SqlDbType.VarChar, 800)) objCommand.Parameters.Add(New SqlParameter("@email", SqlDbType.VarChar, 100)) ' Set the values of these parameters: objCommand.Parameters("@fName").Value = Server.HtmlEncode(txtFname.Text) objCommand.Parameters("@lName").Value = Server.HtmlEncode(txtLname.Text) objCommand.Parameters("@unit").Value = Server.HtmlEncode(txtUnit.Text) objCommand.Parameters("@stnumb").Value = Server.HtmlEncode(txtUnit.Text) objCommand.Parameters("@stname").Value = Server.HtmlEncode(txtStName.Text) objCommand.Parameters("@sttype").Value = Server.HtmlEncode(txtStType.Text) objCommand.Parameters("@city1").Value = Server.HtmlEncode(txtCity.Text) objCommand.Parameters("@prov1").Value = Server.HtmlEncode(txtProv.Text) objCommand.Parameters("@count1").Value = Server.HtmlEncode(txtCountry.Text) objCommand.Parameters("@Postal").Value = Server.HtmlEncode(txtPostal.Text) objCommand.Parameters("@home").Value = Server.HtmlEncode(txtHomePh.Text) objCommand.Parameters("@cell").Value = Server.HtmlEncode(txtCell.Text) objCommand.Parameters("@comment").Value = Server.HtmlEncode(txtComment.Text) objCommand.Parameters("@email").Value = Server.HtmlEncode(txtEmail.Text) ' Open the connection, execute the command, and close the connection. objConnection.Open() objCommand.ExecuteNonQuery() objCommand.Dispose() Response.Redirect("signupcomp.aspx") ' Record is now added... End If End Sub End Classziaulrahman
Member
483 Points
179 Posts
Re: Validation messed my submit function
Apr 21, 2012 05:22 AM|LINK
Create validation group for the Valdiation and Submit button.
Mark answer if it helps.
ziaulrahman
Member
483 Points
179 Posts
Re: Validation messed my submit function
Apr 21, 2012 05:26 AM|LINK
U get a property named Validation Group in both Validation controls and Button Properties.Just give same name at both the properties.
Mark answer if it helps.
Da69Devil
Member
2 Points
17 Posts
Re: Validation messed my submit function
Apr 21, 2012 06:00 AM|LINK
i added the group to all validators and the submit button but i still have the same issue.. i added ValidationGroup="signupValGroup" to them all but still the same thing
ziaulrahman
Member
483 Points
179 Posts
Re: Validation messed my submit function
Apr 21, 2012 06:11 AM|LINK
Dude u cant be adding same validation control to all the controls.Just add validation group to the particular validation controls that u want to invoke on Submit button.
Mark answer if it helps.
Da69Devil
Member
2 Points
17 Posts
Re: Validation messed my submit function
Apr 21, 2012 03:21 PM|LINK
a little help with the code would be nice :)
markfitzme
Star
14411 Points
2226 Posts
Re: Validation messed my submit function
Apr 21, 2012 03:44 PM|LINK
Don't have both buttons call the same exact button click event handler. You can have each one call it's own handler. There is absolutely no reason to have one button handler and try to then determine which button caused the event.
If you ensure that your submit button, and all the validators use the exact same ValidationGroup then you should be ok. On the submit though, you also need to do an if Page.IsValid check to ensure that the validators are saying that everything is correct.
Da69Devil
Member
2 Points
17 Posts
Re: Validation messed my submit function
Apr 21, 2012 03:48 PM|LINK
i tried both way and slit up the button click events and the clear works fine but the submit wont add the record into the database like it used to. before i had that IfPage,IsValid right under the SubButtonClick event and if it was the clear button it ran through the first code Else it ran the submit code and records were added into the database .. then i added the validators and both buttons stopped responding and now i have the clear button working but my submit wont add record to database and i'm not sure why or how this happened
YunJiang
Participant
1124 Points
122 Posts
Re: Validation messed my submit function
May 01, 2012 02:59 AM|LINK
Hi,
I tested your code, you just need to fix the RegularExpressionValidator for Email(TextBox ID="txtEmail")like this:
<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="txtEmail" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>
now it is working
Da69Devil
Member
2 Points
17 Posts
Re: Validation messed my submit function
May 02, 2012 12:43 AM|LINK
Thanks, but i read up on validator controls and fixed it and meant to come back and post. Can you help me with master pages or point to a good resource. I have a root directory where i want the to keep and use the masterpage like a company"Header" but then have subfolders with diiferent aspx apps using the masterpage from above.