I have used a createuserwizard control and added 2 more textboxes. 1 one of the textboxes has a custom validator that will not fire. below is the source code and behind the code. can anyone get it to run on their machine? i am so baffled. thanks in
advance.
<%
@
Page
Language="C#"
AutoEventWireup="true"
CodeFile="newaccount.aspx.cs"
Inherits="newaccount" %>
<!DOCTYPE
html
PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns="http://www.w3.org/1999/xhtml">
<
head
runat="server">
<title></title>
<style
type="text/css">
TextBox sn = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SerialNumberTextBox");
args.IsValid =
false;
string cs =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection conn =
new
SqlConnection(cs);
SqlDataAdapter da =
new
SqlDataAdapter("SELECT * FROM product_info WHERE product_info.Serial_number = @Serial_number
AND product_info.Serial_number NOT IN (SELECT Serial_number FROM users_to_product_info)", conn);
da.SelectCommand.Parameters.Add(
"@Serial_number",
SqlDbType.NChar, 10);
da.SelectCommand.Parameters["@Serial_number"].Value = sn.Text;DataSet
ds = new
DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
args.IsValid = true;
it is definitely a server side control. i tested a custom validator with just a textbox and button not inside the userwizard and it did work. I had this working at one time and haven't changed anything and now it wont work mysteriously.
nkair19
Member
27 Points
50 Posts
custom validation
Feb 27, 2009 02:25 PM|LINK
I have used a createuserwizard control and added 2 more textboxes. 1 one of the textboxes has a custom validator that will not fire. below is the source code and behind the code. can anyone get it to run on their machine? i am so baffled. thanks in advance.
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="newaccount.aspx.cs" Inherits="newaccount" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
html xmlns="http://www.w3.org/1999/xhtml"><
head runat="server"> <title></title> <style type="text/css">
* { margin: 0 0 0 0px; padding: 0;text-align: left;}
</style> </head><
body> <form id="form1" runat="server"> <div style="width: 341px">
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" oncreateduser="CreateUserWizard1_CreatedUser"> <WizardSteps> <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"> <ContentTemplate> <table border="0"> <tr> <td align="center" colspan="2">Sign Up for Your New Account
</td> </tr> <tr> <td align="right"> <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label> </td> <td> <asp:TextBox ID="UserName" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label> </td> <td> <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label> </td> <td> <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label> </td> <td> <asp:TextBox ID="Email" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email" ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security Question:</asp:Label> </td> <td> <asp:TextBox ID="Question" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" ControlToValidate="Question" ErrorMessage="Security question is required." ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security Answer:</asp:Label> </td> <td> <asp:TextBox ID="Answer" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer" ErrorMessage="Security answer is required." ToolTip="Security answer is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right">Serial Number:
</td> <td> <asp:TextBox ID="SerialNumberTextBox" runat="server"></asp:TextBox> <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="SerialNumberTextBox" ErrorMessage="enter a valid serial number" onservervalidate="CustomValidator1_ServerValidate" ValidationGroup="CreateUserWizard1" EnableClientScript="False" ValidateEmptyText="True">*</asp:CustomValidator> </td> </tr> <tr> <td align="right">Company:
</td> <td> <asp:TextBox ID="Company" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Company" ErrorMessage="enter company" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="center" colspan="2"> <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match." ValidationGroup="CreateUserWizard1"></asp:CompareValidator> </td> </tr> <tr> <td align="center" colspan="2" style="color:Red;"> <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal> <asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [users_to_product_info] WHERE [UserId] = @original_UserId AND [Serial_number] = @original_Serial_number" InsertCommand="INSERT INTO [users_to_product_info] ([UserId], [Serial_number]) VALUES (@UserId, @Serial_number) " OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [UserId], [Serial_number] FROM [users_to_product_info]" UpdateCommand="UPDATE [users_to_product_info] SET [Serial_number] = @Serial_number WHERE [UserId] = @original_UserId AND [Serial_number] = @original_Serial_number"> <DeleteParameters> <asp:Parameter Name="original_UserId" Type="Object" /> <asp:Parameter Name="original_Serial_number" Type="String" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Serial_number" Type="String" /> <asp:Parameter Name="original_UserId" Type="Object" /> <asp:Parameter Name="original_Serial_number" Type="String" /> </UpdateParameters> <InsertParameters> <asp:ControlParameter ControlID="SerialNumberTextBox" Name="Serial_number" PropertyName="Text" Type="String" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> <tr> <td align="center" colspan="2" style="color:Red;"> <asp:ValidationSummary ID="ValidationSummary1" runat="server" Height="109px" /> </td> </tr> </table> </ContentTemplate> <CustomNavigationTemplate> <table border="0" cellspacing="5" style="width:100%;height:100%;"> <tr align="right"> <td align="right" colspan="0"> <asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext" Text="Create User" ValidationGroup="CreateUserWizard1" /> </td> </tr> </table> </CustomNavigationTemplate> </asp:CreateUserWizardStep> <asp:CompleteWizardStep runat="server" /> </WizardSteps> </asp:CreateUserWizard>
</div> </form></
body></
html>using
System;using
System.Collections.Generic;using
System.Linq;using
System.Web;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Configuration;using
System.Data.SqlClient;using
System.Data;using
System.Web.Security;public
partial class newaccount : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args){
TextBox sn = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SerialNumberTextBox");args.IsValid =
false; string cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(cs); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM product_info WHERE product_info.Serial_number = @Serial_number AND product_info.Serial_number NOT IN (SELECT Serial_number FROM users_to_product_info)", conn);da.SelectCommand.Parameters.Add(
"@Serial_number", SqlDbType.NChar, 10); da.SelectCommand.Parameters["@Serial_number"].Value = sn.Text;DataSet ds = new DataSet();da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0) args.IsValid = true;}
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e){
TextBox un = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"); SqlDataSource DataSource = (SqlDataSource)CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo"); MembershipUser User = Membership.GetUser(un.Text); object UserGUID = User.ProviderUserKey; DataSource.InsertParameters.Add("UserId", UserGUID.ToString());DataSource.Insert();
}
}
shashankgwl
All-Star
18926 Points
3662 Posts
Re: custom validation
Feb 27, 2009 02:44 PM|LINK
if server side it is not firing then its an issue , if not onclient side then its becoz u've not defined any client event 4 that
All is well if it runs well.
blog
nkair19
Member
27 Points
50 Posts
Re: custom validation
Feb 27, 2009 02:54 PM|LINK
it is definitely a server side control. i tested a custom validator with just a textbox and button not inside the userwizard and it did work. I had this working at one time and haven't changed anything and now it wont work mysteriously.
shashankgwl
All-Star
18926 Points
3662 Posts
Re: custom validation
Feb 28, 2009 10:23 AM|LINK
fine, give a call to Page.Validate() and use IsValid Property in the nextline to proceed
public page_load(...)
{
Page.Validate();
//THIS WILL FIRE ALL YOUR VALIDATION EVENTS AND INTERNALLY SET IsValid property.
if(IsValid)
{
//REST OF THE CODE.
}
}
All is well if it runs well.
blog