M
Morris Neuman
Hi,
I have a web page which allows users logged in to be able to change their
password, their password question and answer and their email address. Though
this info is all on one page, I want the user to be able to change just the
password, or the question and answer, or the email - each component
individually.
I am using the ChangePassword control for the passwrod and custom controls
for the other changes. I have set-up individual RequiresFieldValidators and
set up 2 ValidationGroups (password, question, answer are in Group1, email is
in group2).
When attempting to change the password question and answer I get error:
"AnswerRequiredValidator" is undefined.
When attempting to change the email address I get error
"EmailRequiredValidator" is undefined.
These error occur on the statements -
OnClientClick="javascript:enableValidators(AnswerRequiredValidator,QuestionRequiredValidator,OldPasswordRequiredValidator);"
OnClientClick="javascript:enableValidators(EmailRequiredValidator);"
Can you check my code and see why I would be getting this error?
My code is as follows:
<%@ Page Language="C#" MasterPageFile="~/MasterPage1.master" Title="Change
Password Page" %>
<script runat="server">
protected void ChangePassword1_ChangedPassword(object sender, EventArgs e)
{
}
protected void ChangePasswordQuestion_OnClick(object sender, EventArgs
args)
{
try
{
MembershipUser u = Membership.GetUser(User.Identity.Name);
Boolean result =
u.ChangePasswordQuestionAndAnswer(PasswordTextbox.Text,
QuestionTextbox.Text,
AnswerTextbox.Text);
if (result)
Msg.Text = "Password Question and Answer changed.";
else
Msg.Text = "Password Question and Answer change failed.";
}
catch (Exception e)
{
Msg.Text = "Change failed. Please re-enter your values and try
again.";
}
}
MembershipUser u;
protected void Page_Load(object sender, EventArgs args)
{
u = Membership.GetUser(User.Identity.Name);
if (!IsPostBack)
{
EmailTextBox.Text = u.Email;
}
}
protected void UpdateEmailButton_OnClick(object sender, EventArgs args)
{
try
{
u.Email = EmailTextBox.Text;
Membership.UpdateUser(u);
Msg2.Text = "User e-mail updated.";
}
catch (System.Configuration.Provider.ProviderException e)
{
Msg2.Text = e.Message;
}
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<span style="font-family: Verdana">
<br />
</span>
<table style="width: 582px">
<tr>
<td style="width: 457px; text-align: center; height: 47px;"
colspan="2">
<span style="font-size: large; font-family:
Verdana;">Account Information for </span>
<asp:LoginName ID="LoginName2" runat="server" Width="63px"
Font-Bold="False"
ForeColor="Navy" Font-Size="Large"
style="font-family: Verdana; font-size: large" />
</td>
</tr>
<tr>
<td style="width: 457px; text-align: center; height: 47px;"
colspan="2">
<span style="font-size: small; font-family: Verdana;
font-weight: bold;">Change your password</span><br />
<span style="font-family: Verdana">
<strong>
<asp:HyperLink ID="HyperLink1" runat="server"
Font-Names="Verdana" Font-Size="Smaller"
NavigateUrl="~/RecoverPassword.aspx"
Width="172px">Forgot your password?</asp:HyperLink>
</strong></span>
<br />
</td>
</tr>
<tr>
<td style="width: 457px; height: 150px;" colspan="2">
<asp:ChangePassword ID="ChangePassword1" runat="server"
ContinueDestinationPageUrl="~/Default.aspx" ChangePasswordTitleText=""
Font-Names="Verdana" Font-Size="10pt" Width="453px" Font-Bold="False"
OnChangedPassword="ChangePassword1_ChangedPassword"
CancelDestinationPageUrl="~/Default.aspx">
</asp:ChangePassword>
</td>
</tr>
<tr>
<td style="width: 457px; height: 28px; text-align: center"
colspan="2">
-------------------------------------------------------
</td>
</tr>
</table>
<table>
<tr>
<td style="height: 28px; text-align: center" colspan="2">
<span style="font-size: medium">
<br />
<b style="font-family: Verdana; font-size: small;
font-weight: bold">Change Password Question and Answer</b><br />
<asp:Label ID="Msg" ForeColor="maroon" runat="server"
style="font-size: small; font-family: Verdana;"
/></span>
</td>
</tr>
<tr>
<td style="width: 379px; height: 28px; text-align: right">
<span style="font-size: small; font-family:
Verdana;">Password:</span>
</td>
<td style="width: 400px; height: 28px; text-align: left">
<asp:TextBox ID="PasswordTextbox" runat="server"
TextMode="Password" />
<span style="font-family: Verdana">
<asp:RequiredFieldValidator
ID="OldPasswordRequiredValidator" runat="server"
ControlToValidate="PasswordTextbox"
ForeColor="red" Display="Static" ErrorMessage="*"
style="font-size: small" ValidationGroup="Group1"
/></span>
</td>
</tr>
<tr>
<td style="width: 379px; height: 28px; text-align: right">
<span style="font-family: Verdana; font-size: small;"> <span
style="font-weight: normal">New Password
Question:</span> </span>
</td>
<td style="width: 400px; height: 28px; text-align: left">
<span style="font-family: Verdana"></span>
<asp:TextBox ID="QuestionTextbox" MaxLength="256"
Columns="60" runat="server"
Width="350px" />
<asp:RequiredFieldValidator ID="QuestionRequiredValidator"
runat="server" ControlToValidate="QuestionTextbox"
ForeColor="red" Display="Static" ErrorMessage="*"
style="font-size: small" ValidationGroup="Group1" />
</td>
</tr>
<tr>
<td style="text-align: right; width: 379px;">
<span style="font-size: small; width: 239px; text-align:
right; font-family: Verdana;">
</span>
<span style="font-size: small; width: 239px; text-align:
right; font-family: Verdana;">
New Password Answer:</span></td>
<td style="font-size: small; width: 400px;">
<span style="font-family: Verdana">
<asp:TextBox ID="AnswerTextbox" MaxLength="128" Columns="60"
runat="server" Width="350px" />
<asp:RequiredFieldValidator ID="AnswerRequiredValidator"
runat="server" ControlToValidate="AnswerTextbox"
ForeColor="red" Display="Static" ErrorMessage="*"
style="font-size: small" ValidationGroup="Group1"
/></span>
</td>
</tr>
<tr>
<td style="height: 28px; text-align: center" colspan="2">
<strong>
<asp:Button ID="ChangePasswordQuestionButton" InputType =
"button"
Text="Change Password Question and Answer"
OnClientClick="javascript:enableValidators(AnswerRequiredValidator,QuestionRequiredValidator,OldPasswordRequiredValidator);"
OnClick="ChangePasswordQuestion_OnClick"
runat="server"
ValidationGroup="Group1" /> </strong>
</td>
</tr>
<tr>
<td style="height: 28px; text-align: center" colspan="2">
--------------------------------------------------------</td>
</tr>
</table>
<br />
<table>
<tr>
<td colspan="3" style="height: 27px; text-align: center">
<span style="font-family: Verdana; font-size: small; font-weight:
bold">Change
Email</span><br />
<asp:Label id="Msg2" ForeColor="Maroon" runat="server" Font-Names="Verdana"
Font-Size="Small" /></td>
</tr>
<tr>
<td style="font-family: Verdana; font-size: small; text-align: right;
width: 246px">E-mail Address:</td>
<td style="width: 317px"><asp:TextBox id="EmailTextBox" MaxLength="128"
Columns="30" runat="server" Width="310px" /></td>
<td><asp:RequiredFieldValidator id="EmailRequiredValidator"
runat="server"
ControlToValidate="EmailTextBox"
ForeColor="red"
Display="Static" ErrorMessage="*"
ValidationGroup="Group2" /></td>
</tr>
<tr>
<td style="width: 246px"></td>
<td style="width: 317px"><asp:Button id="UpdateEmailButton"
Text="Update E-mail"
OnClientClick="javascript:enableValidators(EmailRequiredValidator);"
OnClick="UpdateEmailButton_OnClick"
runat="server" /></td>
</tr>
</table>
</asp:Content>
I have a web page which allows users logged in to be able to change their
password, their password question and answer and their email address. Though
this info is all on one page, I want the user to be able to change just the
password, or the question and answer, or the email - each component
individually.
I am using the ChangePassword control for the passwrod and custom controls
for the other changes. I have set-up individual RequiresFieldValidators and
set up 2 ValidationGroups (password, question, answer are in Group1, email is
in group2).
When attempting to change the password question and answer I get error:
"AnswerRequiredValidator" is undefined.
When attempting to change the email address I get error
"EmailRequiredValidator" is undefined.
These error occur on the statements -
OnClientClick="javascript:enableValidators(AnswerRequiredValidator,QuestionRequiredValidator,OldPasswordRequiredValidator);"
OnClientClick="javascript:enableValidators(EmailRequiredValidator);"
Can you check my code and see why I would be getting this error?
My code is as follows:
<%@ Page Language="C#" MasterPageFile="~/MasterPage1.master" Title="Change
Password Page" %>
<script runat="server">
protected void ChangePassword1_ChangedPassword(object sender, EventArgs e)
{
}
protected void ChangePasswordQuestion_OnClick(object sender, EventArgs
args)
{
try
{
MembershipUser u = Membership.GetUser(User.Identity.Name);
Boolean result =
u.ChangePasswordQuestionAndAnswer(PasswordTextbox.Text,
QuestionTextbox.Text,
AnswerTextbox.Text);
if (result)
Msg.Text = "Password Question and Answer changed.";
else
Msg.Text = "Password Question and Answer change failed.";
}
catch (Exception e)
{
Msg.Text = "Change failed. Please re-enter your values and try
again.";
}
}
MembershipUser u;
protected void Page_Load(object sender, EventArgs args)
{
u = Membership.GetUser(User.Identity.Name);
if (!IsPostBack)
{
EmailTextBox.Text = u.Email;
}
}
protected void UpdateEmailButton_OnClick(object sender, EventArgs args)
{
try
{
u.Email = EmailTextBox.Text;
Membership.UpdateUser(u);
Msg2.Text = "User e-mail updated.";
}
catch (System.Configuration.Provider.ProviderException e)
{
Msg2.Text = e.Message;
}
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<span style="font-family: Verdana">
<br />
</span>
<table style="width: 582px">
<tr>
<td style="width: 457px; text-align: center; height: 47px;"
colspan="2">
<span style="font-size: large; font-family:
Verdana;">Account Information for </span>
<asp:LoginName ID="LoginName2" runat="server" Width="63px"
Font-Bold="False"
ForeColor="Navy" Font-Size="Large"
style="font-family: Verdana; font-size: large" />
</td>
</tr>
<tr>
<td style="width: 457px; text-align: center; height: 47px;"
colspan="2">
<span style="font-size: small; font-family: Verdana;
font-weight: bold;">Change your password</span><br />
<span style="font-family: Verdana">
<strong>
<asp:HyperLink ID="HyperLink1" runat="server"
Font-Names="Verdana" Font-Size="Smaller"
NavigateUrl="~/RecoverPassword.aspx"
Width="172px">Forgot your password?</asp:HyperLink>
</strong></span>
<br />
</td>
</tr>
<tr>
<td style="width: 457px; height: 150px;" colspan="2">
<asp:ChangePassword ID="ChangePassword1" runat="server"
ContinueDestinationPageUrl="~/Default.aspx" ChangePasswordTitleText=""
Font-Names="Verdana" Font-Size="10pt" Width="453px" Font-Bold="False"
OnChangedPassword="ChangePassword1_ChangedPassword"
CancelDestinationPageUrl="~/Default.aspx">
</asp:ChangePassword>
</td>
</tr>
<tr>
<td style="width: 457px; height: 28px; text-align: center"
colspan="2">
-------------------------------------------------------
</td>
</tr>
</table>
<table>
<tr>
<td style="height: 28px; text-align: center" colspan="2">
<span style="font-size: medium">
<br />
<b style="font-family: Verdana; font-size: small;
font-weight: bold">Change Password Question and Answer</b><br />
<asp:Label ID="Msg" ForeColor="maroon" runat="server"
style="font-size: small; font-family: Verdana;"
/></span>
</td>
</tr>
<tr>
<td style="width: 379px; height: 28px; text-align: right">
<span style="font-size: small; font-family:
Verdana;">Password:</span>
</td>
<td style="width: 400px; height: 28px; text-align: left">
<asp:TextBox ID="PasswordTextbox" runat="server"
TextMode="Password" />
<span style="font-family: Verdana">
<asp:RequiredFieldValidator
ID="OldPasswordRequiredValidator" runat="server"
ControlToValidate="PasswordTextbox"
ForeColor="red" Display="Static" ErrorMessage="*"
style="font-size: small" ValidationGroup="Group1"
/></span>
</td>
</tr>
<tr>
<td style="width: 379px; height: 28px; text-align: right">
<span style="font-family: Verdana; font-size: small;"> <span
style="font-weight: normal">New Password
Question:</span> </span>
</td>
<td style="width: 400px; height: 28px; text-align: left">
<span style="font-family: Verdana"></span>
<asp:TextBox ID="QuestionTextbox" MaxLength="256"
Columns="60" runat="server"
Width="350px" />
<asp:RequiredFieldValidator ID="QuestionRequiredValidator"
runat="server" ControlToValidate="QuestionTextbox"
ForeColor="red" Display="Static" ErrorMessage="*"
style="font-size: small" ValidationGroup="Group1" />
</td>
</tr>
<tr>
<td style="text-align: right; width: 379px;">
<span style="font-size: small; width: 239px; text-align:
right; font-family: Verdana;">
</span>
<span style="font-size: small; width: 239px; text-align:
right; font-family: Verdana;">
New Password Answer:</span></td>
<td style="font-size: small; width: 400px;">
<span style="font-family: Verdana">
<asp:TextBox ID="AnswerTextbox" MaxLength="128" Columns="60"
runat="server" Width="350px" />
<asp:RequiredFieldValidator ID="AnswerRequiredValidator"
runat="server" ControlToValidate="AnswerTextbox"
ForeColor="red" Display="Static" ErrorMessage="*"
style="font-size: small" ValidationGroup="Group1"
/></span>
</td>
</tr>
<tr>
<td style="height: 28px; text-align: center" colspan="2">
<strong>
<asp:Button ID="ChangePasswordQuestionButton" InputType =
"button"
Text="Change Password Question and Answer"
OnClientClick="javascript:enableValidators(AnswerRequiredValidator,QuestionRequiredValidator,OldPasswordRequiredValidator);"
OnClick="ChangePasswordQuestion_OnClick"
runat="server"
ValidationGroup="Group1" /> </strong>
</td>
</tr>
<tr>
<td style="height: 28px; text-align: center" colspan="2">
--------------------------------------------------------</td>
</tr>
</table>
<br />
<table>
<tr>
<td colspan="3" style="height: 27px; text-align: center">
<span style="font-family: Verdana; font-size: small; font-weight:
bold">Change
Email</span><br />
<asp:Label id="Msg2" ForeColor="Maroon" runat="server" Font-Names="Verdana"
Font-Size="Small" /></td>
</tr>
<tr>
<td style="font-family: Verdana; font-size: small; text-align: right;
width: 246px">E-mail Address:</td>
<td style="width: 317px"><asp:TextBox id="EmailTextBox" MaxLength="128"
Columns="30" runat="server" Width="310px" /></td>
<td><asp:RequiredFieldValidator id="EmailRequiredValidator"
runat="server"
ControlToValidate="EmailTextBox"
ForeColor="red"
Display="Static" ErrorMessage="*"
ValidationGroup="Group2" /></td>
</tr>
<tr>
<td style="width: 246px"></td>
<td style="width: 317px"><asp:Button id="UpdateEmailButton"
Text="Update E-mail"
OnClientClick="javascript:enableValidators(EmailRequiredValidator);"
OnClick="UpdateEmailButton_OnClick"
runat="server" /></td>
</tr>
</table>
</asp:Content>