I'm trying to user recaptcha control in my application. For some reason it's all the time valid. no matter what values I put in recaptcha field it's all the time valid. Any idea what I'm missing?
here is my code
<%# Control Language="C#" CodeBehind="RegisterControl.ascx.cs" AutoEventWireup="true"
Inherits="UserControls.RegisterControl" %>
<%# Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
<asp:Panel ID="PlReg" runat="server" DefaultButton="CreateUserButton">
<div class="Reg_Wrapper">
<span class="failureNotification">
<asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
</span>
<div class="Clear">
</div>
<div class="Reg_ControlName">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label></div>
<div class="Reg_Control">
<asp:TextBox ID="TxtUserName" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator Display="Dynamic" ID="UserNameRequired" runat="server"
ControlToValidate="TxtUserName" CssClass="failureNotification" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
</div>
<div class="Clear">
</div>
<div class="Reg_ControlName">
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label></div>
<div class="Reg_Control">
<asp:TextBox ID="TxtEmail" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator Display="Dynamic" ID="EmailRequired" runat="server" ControlToValidate="TxtEmail"
CssClass="failureNotification" ErrorMessage="E-mail is required." ToolTip="E-mail is required."
ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RevEmail" ControlToValidate="TxtEmail" runat="server"
ErrorMessage="*" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">
<img src="/Images/required.png" alt="Required" />
</asp:RegularExpressionValidator>
</div>
<div class="Clear">
</div>
<div class="Reg_ControlName">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label></div>
<div class="Reg_Control">
<asp:TextBox ID="TxtPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator Display="Dynamic" ID="PasswordRequired" runat="server"
ControlToValidate="TxtPassword" CssClass="failureNotification" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
</div>
<div class="Clear">
</div>
<div class="Reg_ControlName">
<asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Conf. Password:</asp:Label></div>
<div class="Reg_Control">
<asp:TextBox ID="TxtConfirmPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="TxtConfirmPassword" CssClass="failureNotification"
Display="Dynamic" ErrorMessage="Confirm Password is required." ID="ConfirmPasswordRequired"
runat="server" ToolTip="Confirm Password is required." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="TxtPassword"
ControlToValidate="TxtConfirmPassword" CssClass="failureNotification" Display="Dynamic"
ErrorMessage="The Password and Confirmation Password must match." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:CompareValidator>
</div>
<div class="Clear">
</div>
<div class="Reg_ControlName">
</div>
<div class="Reg_Control">
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="my public key"
PrivateKey="my private key" Theme="white" />
</div>
<div class="Clear">
</div>
<div class="Reg_ControlName">
</div>
<div class="Reg_Control">
<asp:Button ID="CreateUserButton" role="button" runat="server" CommandName="MoveNext"
Text="Create User" ValidationGroup="RegisterUserValidationGroup" CssClass="Reg_Button"
OnClick="CreateUserButton_Click" /></div>
<div class="Clear">
</div>
</div>
</asp:Panel>
serverside
protected void CreateUserButton_Click(object sender, EventArgs e)
{
if(Page.IsValid)
{
ErrorMessage.Text = "page is valid";
}
else
{
ErrorMessage.Text = "page is not valid";
}
}
Here's one that works for me. Be sure to insert correct keys on server:
<recaptcha:RecaptchaControl ID="recaptcha" Theme="clean" runat="server"
PublicKey="hiddenxxx" TabIndex="7" ToolTip="Accessible CAPTCHA"
privateKey="hiddenxxx" />
<asp:Label CssClass="captchaLabel" ID="lblResult" runat="server" />
As you can see, I usually keep the CAPTCHA error message separate from the other messages.
Code-behind:
if(Page.IsValid)
{
...
}
else
{
lblResult.Text = "Incorrect!";
lblResult.ForeColor = System.Drawing.Color.Red;
}
i dont think check captcha validation out on page load there should be submit button that you have and you check it out in click event of the button, this is how i use. i think you should check links blove...
http://code.google.com/intl/tr-TR/apis/recaptcha/docs/aspnet.html
http://www.codeproject.com/KB/custom-controls/CaptchaControl.aspx
Related
I have a modal inside an update panel which give information of student when click on argument in a grid view.
In my modal I have also 3 textbox in which the value need to be save when click in save button.
It is not triggering the save button.
Here is my code:
<div class="modal fade" id="studinfo" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Student Info</h4>
<button type="button" class="close"
data-dismiss="modal">
×</button>
</div>
<div class="modal-body">
<asp:UpdatePanel ID="updModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<div class="card h-100">
<div class="card-body">
<ul class="list-group list-group-flush">
<asp:TextBox ID="txtId" Visible="false" runat="server"></asp:TextBox>
<asp:Panel ID="typepannel" CssClass="list-group-item" runat="server">
<asp:Label ID="lbltype" runat="server"
Font-Bold="true" Text="Candidate Type: "></asp:Label>
<asp:Label ID="type" runat="server"
Text=''>
</asp:Label>
</asp:Panel>
<asp:Panel ID="colpanel" CssClass="list-group-item" runat="server">
<asp:Label ID="lblCol" runat="server"
Font-Bold="true" Text="College Attend: "></asp:Label>
<asp:Label ID="college" runat="server"
Text=''>
</asp:Label>
</asp:Panel>
<div class="list-group-item">
<asp:Label ID="lblName" runat="server"
Font-Bold="true" Text="Name: "></asp:Label>
<asp:Label ID="Name" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblNic" runat="server"
Font-Bold="true" Text="Nic: "></asp:Label>
<asp:Label ID="Nic" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblAge" runat="server"
Font-Bold="true" Text="Age: "></asp:Label>
<asp:Label ID="Age" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblAdress" runat="server"
Font-Bold="true" Text="Address: "></asp:Label>
<asp:Label ID="Address" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblacad" runat="server"
Font-Bold="true" Text="Academy: "></asp:Label>
<asp:Label ID="Academy" runat="server"
Text=''>
</asp:Label>
</div>
<h6 class="mt-3 mb-3">Parent in Charge</h6>
<div class="list-group-item">
<asp:Label ID="lblParent" runat="server"
Font-Bold="true" Text="Parent Name: "></asp:Label>
<asp:Label ID="parentName" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblNumber" runat="server"
Font-Bold="true" Text="Parent Contact Number: "></asp:Label>
<asp:Label ID="Number" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblEmail" runat="server"
Font-Bold="true" Text="Parent Email Address: "></asp:Label>
<asp:Label ID="Email" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblResult" runat="server"
Font-Bold="true" Text="Result: "></asp:Label>
<asp:DropDownList ID="ddlResult"
CssClass="select form-control"
runat="server">
</asp:DropDownList>
</div>
<div class="list-group-item">
<asp:Label ID="lblMarks" runat="server" Font-Bold="true" Text="Marks: "></asp:Label>
<asp:TextBox runat="server" ID="txtMarks"
CssClass="form-control form-control-lg" />
<asp:RequiredFieldValidator ID="rfvMarks" runat="server"
Display="Dynamic" ForeColor="Red"
ControlToValidate="txtMarks"
SetFocusOnError="true"
ErrorMessage="Marks is Mandatory">
</asp:RequiredFieldValidator>
<asp:CompareValidator ID="cmpVMarks" runat="server"
ControlToValidate="txtMarks"
Operator="DataTypeCheck"
Type="Double"
SetFocusOnError="true"
Display="Dynamic"
Text="Incorect data type"
ForeColor="Red"
ErrorMessage="Invalid">
</asp:CompareValidator>
<asp:RegularExpressionValidator ID="revPhone"
runat="server"
ControlToValidate="txtMarks"
SetFocusOnError="true"
Display="Dynamic"
ForeColor="Red"
ValidationExpression="^\d\d+(\.[1-9])?$"
ErrorMessage="Invalid">
</asp:RegularExpressionValidator>
</div>
<div class="list-group-item">
<asp:Label ID="lblpurcentage" runat="server"
Font-Bold="true" Text="Purcentage : "></asp:Label>
<asp:TextBox runat="server" ID="txtpur"
CssClass="form-control form-control-lg" />
<asp:RequiredFieldValidator
ID="rfvpur" runat="server"
Display="Dynamic" ForeColor="Red"
ControlToValidate="txtpur"
SetFocusOnError="true"
ErrorMessage="Purcentage is Mandatory">
</asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvpur" runat="server"
ControlToValidate="txtpur"
Operator="DataTypeCheck"
Type="Double"
SetFocusOnError="true"
Display="Dynamic"
Text="Incorect data type"
ForeColor="Red"
ErrorMessage="Invalid">
</asp:CompareValidator>
</div>
</ul>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnSave" OnClick="btnSave_Click"
CssClass="btn btn-success btn-block" runat="server" Text="Save" />
</div>
</div>
To make this data appear in modal I used updModal.Update(); in the button where I use to call the modal.
Here is my code behind of save button:
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
string id = txtId.Text;
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update tblStudent set stud_result=#res,stud_purcentage=#pur,stud_totalMarks=#marks where stud_Id=#id";
cmd.Parameters.AddWithValue("#id", id);
cmd.Parameters.AddWithValue("#res", ddlResult.SelectedValue);
cmd.Parameters.AddWithValue("#pur", txtpur.Text.Trim());
cmd.Parameters.AddWithValue("#marks", txtMarks.Text.Trim());
con.Open();
cmd.Connection = con;
updModal.Update();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, GetType(), "LaunchServerSide",
"$(function () { showUErrorModal(); });", true);
}
finally
{
con.Close();
}
}
When I have try to put the button inside the update panel it freeze the app when I triger the button.
Can someone please please help me with that? Thank you in advance.
i have made registeration form, forgot password and login form in a single aspx page . I am using css to style the whole form. I am using 3 form tags. Here is code:
ASMX
<form id="form1" runat="server" visible="true">
<ul>
<li>
<asp:TextBox ID="email" runat="server" TextMode="email" placeholder="Email" OnTextChanged="email_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="email" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*Requied</asp:RequiredFieldValidator>
</li>
<li>
<asp:TextBox ID="password" runat="server" TextMode="Password" placeholder="Password" OnTextChanged="password_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="password" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*Requied</asp:RequiredFieldValidator>
</li>
<li>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</li>
<li>
<asp:Label ID="Invalid" runat="server" Text="Invalid Username or Password" Visible="False" ></asp:Label>
<asp:Label ID="Try" runat="server" Text="You can't try again ,Register Your Self" Visible="False"></asp:Label>
</li>
</ul>
</form>
<form runat="server" id="form2" visible="false">
<ul>
<li>
<asp:TextBox ID="username" runat="server" MaxLength="15" placeholder="UserName" OnTextChanged="username_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="username" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input user name</asp:RequiredFieldValidator>
<asp:Label ID="userchk" runat="server" ForeColor="Red"></asp:Label>
</li>
<li>
<asp:TextBox ID="EmailR" runat="server" placeholder="Email (must be valid)" OnTextChanged="EmailR_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="EmailR" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input email</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="EmailR" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="RegularExpressionValidator" ForeColor="Red">Input Valid Email</asp:RegularExpressionValidator>
</li>
<li>
<asp:TextBox ID="FirstName" runat="server" placeholder="FirstName" MaxLength="15" OnTextChanged="FirstName_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="FirstName" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input first name</asp:RequiredFieldValidator>
<asp:Label ID="chkemail" runat="server" ForeColor="Red"></asp:Label>
</li>
<li>
<asp:TextBox ID="LastName" runat="server" placeholder="Lastname" MaxLength="15" OnTextChanged="TextBox3_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="LastName" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input Last name</asp:RequiredFieldValidator>
</li>
<li>
<asp:TextBox ID="Pass" runat="server" placeholder="Password" TextMode="Password" MaxLength="15" OnTextChanged="Pass_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="Pass" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input password</asp:RequiredFieldValidator>
</li>
<li>
<asp:TextBox ID="Cpass" runat="server" placeholder="Confirm Password" TextMode="Password" MaxLength="15" OnTextChanged="Cpass_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="Cpass" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Enter the Confirm Password </asp:RequiredFieldValidator>
</ul>
</form>
<form runat="server" visible="false" id="form3">
<ul>
<li>
<asp:TextBox ID="SendEmail" runat="server" TextMode="Email" placeholder="Enter Email" OnTextChanged="SendEmail_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="SendEmail" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*Requied</asp:RequiredFieldValidator>
</li>
<li>
<asp:Button runat="server" text="Send email" OnClick="SendMail_Click" CssClass="button" Visible="true" CausesValidation="False"/>
</li>
<li>
<asp:Label ID="ml" runat="server" Text="Email sended Sucessfully" Visible="False"></asp:Label>
<asp:Label ID="ml0" runat="server" Text="Email Didn't Match " Visible="False"></asp:Label>
</li>
</ul>
</form>
I used following Js in toglling categories:
JS
<script>
$(document).ready(function () {
$("#list1").click(function () {
$("#form1").fadeIn("slow");
$("#form2").css("display", "none");
$("#form3").css("display", "none");
});
$("#list2").click(function () {
$("#form2").fadeIn("slow");
$("#form2").css("visible", "true");
$("#form1").css("display", "none");
$("#form3").css("display", "none");
});
$("#list3").click(function () {
$("#form3").fadeIn("slow");
$("#form3").css("visible", "true");
$("#form2").css("display", "none");
$("#form1").css("display", "none");
});
});
</script>
and here is my css FORMS
I have to use multiple forms in any case .. can anyone help please??
I am trying to create a user with the create user wizard. For email validation i am using regualr expression control. I given ControlToValidate property to the id of the email text box. When I given wrong email Id and click on create user it is showing error message what i configured in the <asp:RegularExpressionValidator>but it is going to next step and saying user created succesfully. How to stop register the user when email format is wrong. I am trying to modify the CreatingUser event like this
protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
bool allfieldsstatus = false;
RegularExpressionValidator emailvalidator = (RegularExpressionValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("emailvalidator");
if (!emailvalidator.Visible)
{
allfieldsstatus = true;
}
if (allfieldsstatus)
{
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}
But this is not working. The visibility property not at all showing. I tried in another way in if condition as
if(!emailvalidator.ErrorMessage.length!=0)
{
allfieldstatus = true;
}
This is also not working. Because the ErrorMessage property is always be there in configuration of <asp:RegularExpressionValidator >
What is the solution for this?
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
CssClass="createUseWizard" AutoGeneratePassword="True" ContinueDestinationPageUrl="~/Account/AdminRegister.aspx"
CreateUserButtonText="Register User"
OnCreatedUser="CreateUserWizard1_CreatedUser" BorderStyle="None"
DisplayCancelButton="True" oncreatinguser="CreateUserWizard1_CreatingUser"
LoginCreatedUser="False">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<div id="registerUserDiv">
<div id="registerUserHeader">
Register New User
</div>
<div>
<div class="registerUserLable">
<asp:Label ID="UserNameLabel" runat="server" Text="User Name" AssociatedControlID="UserName"></asp:Label>
</div>
<div class="inputTextbox">
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator CssClass="showInRed" ID="UserIDrequired" runat="server" ControlToValidate="UserName"
ErrorMessage="Email is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1"
SetFocusOnError="True">*</asp:RequiredFieldValidator>
</div>
</div>
<div>
<div class="registerUserLable">
<asp:Label ID="Label1" runat="server" Text="E-mail" AssociatedControlID="Email"></asp:Label></div>
</div>
<div class="inputTextbox">
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator CssClass="showInRed" ID="RequiredFieldValidator1" runat="server"
ControlToValidate="Email" ErrorMessage="E-mail is required." ToolTip="E-mail is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</div>
<div>
<div class="registerUserLable">
<asp:Label ID="Label2" Text="Select Role" runat="server" />
</div>
<div class="inputTextbox">
<asp:DropDownList ID="rolesDropdown" runat="server">
</asp:DropDownList>
</div>
</div>
<div>
<div class="errorEmail">
<asp:RegularExpressionValidator ID="emailvalidator" runat="server"
ErrorMessage="Email Should be in correct format" ControlToValidate="Email"
SetFocusOnError="True"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
Display="Dynamic"></asp:RegularExpressionValidator>
</div>
</div>
<div>
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</div>
</div>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
In general, you should check if validation passed with the IsValid property of single validator controls or of the Page itself:
if (!emailvalidator.IsValid) {
e.Cancel = true;
}
or
if (!Page.IsValid) {
e.Cancel = true;
}
For the wizard, you could perform this check in the NextButtonClick and FinishButtonClick event handlers.
If you think it's RegExp problem try this:
/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i
How I remove 'Current/Old Password' section from ChangePassword control in asp.net.
When I remove this section,I get following error.
ChangeUserPassword: ChangePasswordTemplate does not contain an IEditableTextControl with ID CurrentPassword for the current password.
I only need 'New Password' and 'Confirm new password' section
Edit_______________________
<asp:ChangePassword ID="ChangeUserPassword" runat="server" EnableViewState="false"
RenderOuterTable="false">
<ChangePasswordTemplate>
<span class="failureNotification">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</span>
<asp:ValidationSummary ID="ChangeUserPasswordValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="ChangeUserPasswordValidationGroup" />
<div class="accountInfo">
<fieldset class="changePassword">
<legend>Account Information</legend>
<%--<p>
<asp:Label ID="CurrentPasswordLabel" runat="server" AssociatedControlID="CurrentPassword">Old Password:</asp:Label>
<asp:TextBox ID="CurrentPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="CurrentPasswordRequired" runat="server" ControlToValidate="CurrentPassword"
CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Old Password is required."
ValidationGroup="ChangeUserPasswordValidationGroup">*</asp:RequiredFieldValidator>
</p>--%>
<p>
<asp:Label ID="NewPasswordLabel" runat="server" AssociatedControlID="NewPassword">New Password:</asp:Label>
<asp:TextBox ID="NewPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewPasswordRequired" runat="server" ControlToValidate="NewPassword"
CssClass="failureNotification" ErrorMessage="New Password is required." ToolTip="New Password is required."
ValidationGroup="ChangeUserPasswordValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:Label ID="ConfirmNewPasswordLabel" runat="server" AssociatedControlID="ConfirmNewPassword">Confirm New Password:</asp:Label>
<asp:TextBox ID="ConfirmNewPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmNewPasswordRequired" runat="server" ControlToValidate="ConfirmNewPassword"
CssClass="failureNotification" Display="Dynamic" ErrorMessage="Confirm New Password is required."
ToolTip="Confirm New Password is required." ValidationGroup="ChangeUserPasswordValidationGroup">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="NewPasswordCompare" runat="server" ControlToCompare="NewPassword"
ControlToValidate="ConfirmNewPassword" CssClass="failureNotification" Display="Dynamic"
ErrorMessage="The Confirm New Password must match the New Password entry." ValidationGroup="ChangeUserPasswordValidationGroup">*</asp:CompareValidator>
</p>
</fieldset>
<p class="submitButton">
<%--<asp:Button ID="CancelPushButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"/>--%>
<<Back
<asp:Button ID="ChangePasswordPushButton" runat="server" Text="Change Password"
ValidationGroup="ChangeUserPasswordValidationGroup"
onclick="ChangePasswordPushButton_Click" />
</p>
</div>
</ChangePasswordTemplate>
</asp:ChangePassword>
I am using the built-in register module in asp.net application for registering new users.
I am trying to set the role for the user when they are registering but for some reason I can't access the textbox control in the backend code to add the new user to the selected role, I am trying to find the textbox with this code too, but it returns null, meaning that the control can't be found:
TextBox txtUsername = (TextBox)Page.FindControl("UserName");
Roles.AddUserToRole(txtUsername.Text, "User");
Also, here is the html markup for the register module:
<asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
<ContentTemplate>
<h2>
Create a New Account
</h2>
<p>
Use the form below to create a new account.
</p>
<p>
Passwords are required to be a minimum of <%= Membership.MinRequiredPasswordLength %> characters in length.
</p>
<span class="failureNotification">
<asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
</span>
<asp:ValidationSummary ID="RegisterUserValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="RegisterUserValidationGroup"/>
<div class="accountInfo">
<fieldset class="register">
<legend>Account Information</legend>
<p>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required."
ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
<asp:TextBox ID="Email" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email"
CssClass="failureNotification" ErrorMessage="E-mail is required." ToolTip="E-mail is required."
ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
<asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required."
ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
<asp:TextBox ID="ConfirmPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="ConfirmPassword" CssClass="failureNotification" Display="Dynamic"
ErrorMessage="Confirm Password is required." ID="ConfirmPasswordRequired" runat="server"
ToolTip="Confirm Password is required." ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword"
CssClass="failureNotification" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="RegisterUserValidationGroup">*</asp:CompareValidator>
</p>
</fieldset>
<p class="submitButton">
<asp:Button ID="CreateUserButton" runat="server" CommandName="MoveNext" Text="Create User"
ValidationGroup="RegisterUserValidationGroup"/>
</p>
</div>
</ContentTemplate>
<CustomNavigationTemplate>
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
Any idea what am I doing wrong?
Thanks, Laziale
That's because your UserName text box is not a direct child of the page. It is nested within many controls. Here's how, recursively, you can search through all the controls in your page to get an instance of your UserName text box:
private TextBox getUserNameTextBox(ControlCollection ctls)
{
foreach (Control c in ctls)
{
if (c is System.Web.UI.WebControls.TextBox)
{
if (c.ID == "UserName")
return c;
}
if (c.HasControls())
{
getAllCtl(c.Controls);
}
}
return null;
}
YourUserNameTextBox = getuserNameTextBox(Page.Controls);