PasswordRecoveryAdapter doesn't display username and question for templated views

Last post 02-17-2008 11:02 PM by bdemarzo. 3 replies.

Sort Posts:

  • PasswordRecoveryAdapter doesn't display username and question for templated views

    02-15-2008, 5:25 PM
    • Member
      point Member
    • gborisl
    • Member since 02-15-2008, 10:09 PM
    • Posts 5

    It looks like that if you use the PasswordRecoveryAdapter with templated PasswordRecovery control, the username and security question are not displayed in the question view.

    In the RenderContents method of the PasswordRecoveryAdapter the adapter neglects to populate these child controls before rendering them.

    Proposed solution:

    Call the following method from the RenderContents method before rendering the templated question view:

            /// <summary>
    /// UpdateQuestionContainer
    /// Updates the question and username literal in the templated question view of the password recovery
    /// Otherwise, if rendered with adapter, the question view is empty
    /// </summary>
    /// <param name="passwordRecovery">The password recovery.</param>
    private void UpdateQuestionContainer(PasswordRecovery passwordRecovery)
    {
    Literal questionLiteral = passwordRecovery.QuestionTemplateContainer.FindControl("Question") as Literal;
    if (questionLiteral != null)
    questionLiteral.Text = passwordRecovery.Question;

    string userName = passwordRecovery.UserName;
    // The username is not available in question view
    // Obtain the username from the textbox in the username view
    if (String.IsNullOrEmpty(userName)) {
    ITextControl textbox = passwordRecovery.UserNameTemplateContainer.FindControl("UserName") as ITextControl;
    if (textbox != null)
    userName = textbox.Text;
    }
    Literal usernameLiteral = passwordRecovery.QuestionTemplateContainer.FindControl("UserName") as Literal;
    if (usernameLiteral != null)
    usernameLiteral.Text = userName;
    }

     

    You might need some additional checks to improve robustness.
     

    Filed under:
  • Re: PasswordRecoveryAdapter doesn't display username and question for templated views

    02-17-2008, 4:32 PM
    • Member
      435 point Member
    • bdemarzo
    • Member since 07-02-2002, 4:05 AM
    • New York
    • Posts 168

     I haven't stepped through this code and I don't have any walkthroughs / test pages for this, but looking at the code of PasswordRecoveryAdapter.cs, I see this:

                        else if ((_state == State.Question) || (_state == State.AnswerLookupError))
                        {
                            if ((passwordRecovery.QuestionTemplate != null) && (passwordRecovery.QuestionTemplateContainer != null))
                            {
                                foreach (Control c in passwordRecovery.QuestionTemplateContainer.Controls)
                                {
                                    c.RenderControl(writer);
                                }
                            }
                            else
                            {
                                WriteTitlePanel(writer, passwordRecovery);
                                WriteInstructionPanel(writer, passwordRecovery);
                                WriteHelpPanel(writer, passwordRecovery);
                                WriteUserPanel(writer, passwordRecovery);
                                WriteQuestionPanel(writer, passwordRecovery);
                                WriteAnswerPanel(writer, passwordRecovery);
                                if (_state == State.AnswerLookupError)
                                {
                                    WriteFailurePanel(writer, passwordRecovery);
                                }
                                WriteSubmitPanel(writer, passwordRecovery);
                            }
                        }
    

     That code seems to (on paper, at least) display the template control OR display each of the question/answer fields. Does the code above not run when you step through, or does it not render what it is intended to render?

    If someone wants to add some WalkThru pages for the membership controls and add them as a patch to the CodePlex project, it would be very useful (especially if there could be a mock implementation of the underlying database!).
     

  • Re: PasswordRecoveryAdapter doesn't display username and question for templated views

    02-17-2008, 8:54 PM
    • Member
      point Member
    • gborisl
    • Member since 02-15-2008, 10:09 PM
    • Posts 5

    The code above runs but doesn't render the contents correctly.

    The problem is that before rendering all the child controls under passwordRecovery.QuestionTemplateContainer the special literals in the template (UserName and Question) have to be populated with the previously entered username and the security question retrieved from the membership database. The control's default rendering takes care of that but the adapter's rendering doesn't seem to.

  • Re: PasswordRecoveryAdapter doesn't display username and question for templated views

    02-17-2008, 11:02 PM
    • Member
      435 point Member
    • bdemarzo
    • Member since 07-02-2002, 4:05 AM
    • New York
    • Posts 168

    I understand now. :)

    Feel free to submit the revised code as a patch to the CodePlex project (http://www.codeplex.com/cssfriendly).

     

Page 1 of 1 (4 items)