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
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 Class