I've been struggling with this. I want to set the continue button as the default and the currentpassword textbox as the focus in a changepassword control. I keep getting null reference errors though. Here is my code with several versions that I tried
with none of them working:
Protected
Sub Page_Load(ByVal sender
As Object,
ByVal e As System.EventArgs)
Handles Me.Load
If Not IsPostBack
Then
Dim PwdChg As ChangePasswordPwdChg =
CType(Me.LoginView1.FindControl("ChangePassword1"), ChangePassword)
Page.Form.DefaultButton = PwdChg.FindControl(
"ChangePasswordContainerID$ChangePasswordPushButton").UniqueID
Dim CurrentPassword
As TextBox
I had this problem aswell. I solved it 3 min ago :).
The thing that I did to solve it is as follow.
<div mce_keep="true">Convert the control to a template.</div>
<div mce_keep="true">Place as first control in your changepasswordtemplate a panel.</div>
<div mce_keep="true">set the defaultbutton to ChangePasswordPushButton</div>
<div mce_keep="true">Place the end tag of the panel just before the closing tag of the changepasswordtemplate</div>
The code:
<asp:ChangePassword ID="ChangePassword1" runat="server">
<ChangePasswordTemplate>
<asp:Panel ID="m_pnlChangePassword" runat="server" DefaultButton="ChangePasswordPushButton">
//The controls to change your password
</asp:Panel>
</ChangePasswordTemplate>
</asp:ChangePassword>
Some other tips:
To set focus to the control, Set in your page_load the following:
ChangePassword1.Focus();
Want to see your errormessages in a validationsummary??
Place a validationsummary just beyond the closing tag of the changepassword control. Don't place it inside it because then you get errors after changing your password. (error comes just between password change button click and opening the completion step)
MDCragg
Member
17 Points
145 Posts
How do I set the default button and the focus in a changepassword control?
Sep 13, 2007 11:50 AM|LINK
Hi,
I've been struggling with this. I want to set the continue button as the default and the currentpassword textbox as the focus in a changepassword control. I keep getting null reference errors though. Here is my code with several versions that I tried with none of them working:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then
Dim PwdChg As ChangePasswordPwdChg = CType(Me.LoginView1.FindControl("ChangePassword1"), ChangePassword)Page.Form.DefaultButton = PwdChg.FindControl(
"ChangePasswordContainerID$ChangePasswordPushButton").UniqueID Dim CurrentPassword As TextBoxCurrentPassword =
CType(PwdChg.FindControl("ChangePasswordContainerID$CurrentPassword"), TextBox)CurrentPassword.Focus()
End If
end subI also tried these variations on the code but they did not work:
(...for default button)
Page.Form.DefaultButton = PwdChg.FindControl(
"ChangePasswordContainer$ChangePasswordPushButton").UniqueIDPage.Form.DefaultButton = PwdChg.FindControl(
"ChangePasswordPushButton").UniqueID(...for focus)
CurrentPassword =
CType(PwdChg.FindControl("ChangePasswordTemplateContainerID$CurrentPassword"), TextBox)CurrentPassword =
CType(PwdChg.ChangePasswordTemplateContainer.FindControl("CurrentPassword"), TextBox)CurrentPassword =
CType(PwdChg.ChangePasswordTemplateContainer.NamingContainer.FindControl("CurrentPassword"), TextBox)Any help anybody can offer is appreciated. Thank you in advance...MDCragg
LockTar
Member
69 Points
52 Posts
Re: How do I set the default button and the focus in a changepassword control?
Mar 24, 2009 12:01 AM|LINK
Hello,
I had this problem aswell. I solved it 3 min ago :).
The thing that I did to solve it is as follow.
The code:
<asp:ChangePassword ID="ChangePassword1" runat="server"> <ChangePasswordTemplate> <asp:Panel ID="m_pnlChangePassword" runat="server" DefaultButton="ChangePasswordPushButton"> //The controls to change your password </asp:Panel> </ChangePasswordTemplate> </asp:ChangePassword>Some other tips:
To set focus to the control, Set in your page_load the following:ChangePassword1.Focus();
Want to see your errormessages in a validationsummary??
Place a validationsummary just beyond the closing tag of the changepassword control. Don't place it inside it because then you get errors after changing your password. (error comes just between password change button click and opening the completion step)
Code:
</asp:Panel> </ChangePasswordTemplate> </asp:ChangePassword> <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="ChangePassword1" />With Css you can let it look like one control. It work for me :-)LockTar
Member
69 Points
52 Posts
Re: How do I set the default button and the focus in a changepassword control?
Mar 24, 2009 12:02 AM|LINK
Sorry.. double post of solution because of loading error on this forum....