changepasswordtemplate.. findcontrol on textboxes?

J

jobs

RE: changepassword template.. findcontrol on textboxes?

I've done this before for formviews and grdviews.. but somehow i am
unable to test the value of changepassword text box ?

Getting this error:
Object reference not set to an instance of an object.



my simple code below . I understand I'm circumventing the delivered
Validators and error message literal. Reason is I want my master page
error popup for that.



<%@ Page Language="VB" AutoEventWireup="false" MasterPageFile="~/Main/
MasterPage.master"
CodeFile="ChangePassword.aspx.vb" Inherits="Service_test" %>
<%@ MasterType virtualpath="~/Main/MasterPage.master" %>
<asp:Content ID="other" ContentPlaceHolderID="Content1"
runat="Server">
<h3>
Change Password
</h3>

<div style="position: relative; left: 20px">
<asp:ChangePassword Width="500px"
ID="ChangePassword1" runat="server" >
<ChangePasswordTemplate>
<br />
<asp:Label ID="CurrentPasswordLabel" skinid="retailer"
runat="server" AssociatedControlID="CurrentPassword">Password:</
asp:Label>
<br />
<asp:TextBox ID="CurrentPassword" skinid="Retailer"
runat="server" CssClass="RTTextbox" TextMode="Password"></asp:TextBox>
<br />
<asp:Label ID="NewPasswordLabel" skinid="Retailer"
runat="server" AssociatedControlID="NewPassword">New Password:</
asp:Label>
<br />
<asp:TextBox ID="NewPassword" skinid="Retailer"
runat="server" TextMode="Password"></asp:TextBox>
<br />
<asp:Label ID="ConfirmNewPasswordLabel" SkinID="Retailer"
runat="server" AssociatedControlID="ConfirmNewPassword">Confirm New
Password:</asp:Label>
<br />
<asp:TextBox ID="ConfirmNewPassword" runat="server"
skinid="Retailer" TextMode="Password"></asp:TextBox>
<br />
<asp:Literal ID="FailureText" runat="server" visible="False"
EnableViewState="False"></asp:Literal>
<br />
<asp:Button ID="ChangePasswordPushButton" runat="server"
skinid="Retailer" CommandName="ChangePassword" Text="Change Password"
ValidationGroup="ChangePassword1"
OnClick="ChangePasswordPushButton_Click" />
<asp:Button ID="CancelPushButton" SkinID="Retailer"
runat="server" BackColor="#0272A6" BorderColor="Gray"
CausesValidation="False" CommandName="Cancel"
Text="Cancel" />
</ChangePasswordTemplate>
</asp:ChangePassword>
</div>

</asp:Content>



Imports system.web.security.membership
Imports system.web.security.Roles


Partial Class Service_test
Inherits System.Web.UI.Page

Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
If CType(ChangePassword1.FindControl("FailureText"),
Literal).Text <> "" Then
Master.ErrorMsg = "ERROR: " +
CType(ChangePassword1.FindControl("FailureText"), Literal).Text
Return
End If

End Sub


Protected Sub ChangePasswordPushButton_Click(ByVal sender As
Object, ByVal e As System.EventArgs)
If CType(ChangePassword1.FindControl("NewPassword"),
TextBox).Text <>
CType(ChangePassword1.FindControl("ConfirmNewPassword"), TextBox).Text
Then
Master.ErrorMsg = "ERROR: Passwords do not match."
Return
End If
End Sub
End Class


Thanks for any help or information!
 
J

johnadriano

RE: changepassword template.. findcontrol on textboxes?

I've done this before for formviews and grdviews.. but somehow i am
unable to test the value of changepassword text box ?

Getting this error:
Object reference not set to an instance of an object.

my simple code below . I understand I'm circumventing the delivered
Validators and error message literal. Reason is I want my master page
error popup for that.

<%@ Page Language="VB" AutoEventWireup="false" MasterPageFile="~/Main/
MasterPage.master"
CodeFile="ChangePassword.aspx.vb" Inherits="Service_test" %>
<%@ MasterType virtualpath="~/Main/MasterPage.master" %>
<asp:Content ID="other" ContentPlaceHolderID="Content1"
runat="Server">
<h3>
Change Password
</h3>

<div style="position: relative; left: 20px">
<asp:ChangePassword Width="500px"
ID="ChangePassword1" runat="server" >
<ChangePasswordTemplate>
<br />
<asp:Label ID="CurrentPasswordLabel" skinid="retailer"
runat="server" AssociatedControlID="CurrentPassword">Password:</
asp:Label>
<br />
<asp:TextBox ID="CurrentPassword" skinid="Retailer"
runat="server" CssClass="RTTextbox" TextMode="Password"></asp:TextBox>
<br />
<asp:Label ID="NewPasswordLabel" skinid="Retailer"
runat="server" AssociatedControlID="NewPassword">New Password:</
asp:Label>
<br />
<asp:TextBox ID="NewPassword" skinid="Retailer"
runat="server" TextMode="Password"></asp:TextBox>
<br />
<asp:Label ID="ConfirmNewPasswordLabel" SkinID="Retailer"
runat="server" AssociatedControlID="ConfirmNewPassword">Confirm New
Password:</asp:Label>
<br />
<asp:TextBox ID="ConfirmNewPassword" runat="server"
skinid="Retailer" TextMode="Password"></asp:TextBox>
<br />
<asp:Literal ID="FailureText" runat="server" visible="False"
EnableViewState="False"></asp:Literal>
<br />
<asp:Button ID="ChangePasswordPushButton" runat="server"
skinid="Retailer" CommandName="ChangePassword" Text="Change Password"
ValidationGroup="ChangePassword1"
OnClick="ChangePasswordPushButton_Click" />
<asp:Button ID="CancelPushButton" SkinID="Retailer"
runat="server" BackColor="#0272A6" BorderColor="Gray"
CausesValidation="False" CommandName="Cancel"
Text="Cancel" />
</ChangePasswordTemplate>
</asp:ChangePassword>
</div>

</asp:Content>

Imports system.web.security.membership
Imports system.web.security.Roles

Partial Class Service_test
Inherits System.Web.UI.Page

Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
If CType(ChangePassword1.FindControl("FailureText"),
Literal).Text <> "" Then
Master.ErrorMsg = "ERROR: " +
CType(ChangePassword1.FindControl("FailureText"), Literal).Text
Return
End If

End Sub

Protected Sub ChangePasswordPushButton_Click(ByVal sender As
Object, ByVal e As System.EventArgs)
If CType(ChangePassword1.FindControl("NewPassword"),
TextBox).Text <>
CType(ChangePassword1.FindControl("ConfirmNewPassword"), TextBox).Text
Then
Master.ErrorMsg = "ERROR: Passwords do not match."
Return
End If
End Sub
End Class

Thanks for any help or information!



This should do the trick

Protected Sub ChangePasswordPushButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs)
Dim NewPassword As TextBox =
CType(ChangePassword1.ChangePasswordTemplateContainer.FindControl("NewPassword"),
TextBox)
Dim ConfirmNewPassword As TextBox =
CType(ChangePassword1.ChangePasswordTemplateContainer.FindControl("ConfirmNewPassword"),
TextBox)

If trim(NewPassword.Text) <> trim(ConfirmNewPassword.Text)
Then
Master.ErrorMsg = "ERROR: Passwords do not match."
Return
End If
End Sub


Hope this helps

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top