Patch to LoginAdapter.cs To Fix Dynamic Links

Jul 17, 2007 at 8:47 PM
Noticed in one of our sites that uses a LoginAdapter within a master page to display the adapter in the same location throughout the site that it did not dynamically adjust links to registration and password recovery to the correct locations as the child page changed folder location within the folder hierarchy. The following source code adjustments should fix this issue. Please note the use of the helper function Extender.ResolveUrl() with the WebControlAdapterExtender.WriteLink() function to resolve the correct Url.

private void WriteHelpPanel(HtmlTextWriter writer, Login login)
        {
            if ((!String.IsNullOrEmpty(login.HelpPageIconUrl)) || (!String.IsNullOrEmpty(login.HelpPageText)))
            {
                WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-HelpPanel", "");
                WebControlAdapterExtender.WriteImage(writer, login.HelpPageIconUrl, "Help");
                WebControlAdapterExtender.WriteLink(writer, login.HyperLinkStyle.CssClass, Extender.ResolveUrl(login.HelpPageUrl), "Help", login.HelpPageText);
                WebControlAdapterExtender.WriteEndDiv(writer);
            }
        }

private void WriteSubmitPanel(HtmlTextWriter writer, Login login)
        {
            string id = "Login";
            string idWithType = WebControlAdapterExtender.MakeIdWithButtonType(id, login.LoginButtonType);
            Control btn = login.FindControl(idWithType);
            if (btn != null)
            {
                Page.ClientScript.RegisterForEventValidation(btn.UniqueID);
 
                WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-SubmitPanel", "");
 
                PostBackOptions options = new PostBackOptions(btn, "", "", false, false, false, true, true, login.UniqueID);
                string javascript = "javascript:" + Page.ClientScript.GetPostBackEventReference(options);
                javascript = Page.Server.HtmlEncode(javascript);
 
                Extender.WriteSubmit(writer, login.LoginButtonType, login.LoginButtonStyle.CssClass, id, Extender.ResolveUrl(login.LoginButtonImageUrl), javascript, login.LoginButtonText);
 
                WebControlAdapterExtender.WriteEndDiv(writer);
            }
        }

private void WriteCreateUserPanel(HtmlTextWriter writer, Login login)
        {
            if ((!String.IsNullOrEmpty(login.CreateUserUrl)) || (!String.IsNullOrEmpty(login.CreateUserText)))
            {
                WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-CreateUserPanel", "");
                WebControlAdapterExtender.WriteImage(writer, login.CreateUserIconUrl, "Create user");
                WebControlAdapterExtender.WriteLink(writer, login.HyperLinkStyle.CssClass, Extender.ResolveUrl(login.CreateUserUrl), "Create user", login.CreateUserText);
                WebControlAdapterExtender.WriteEndDiv(writer);
            }
        }

private void WritePasswordRecoveryPanel(HtmlTextWriter writer, Login login)
        {
            if ((!String.IsNullOrEmpty(login.PasswordRecoveryUrl)) || (!String.IsNullOrEmpty(login.PasswordRecoveryText)))
            {
                WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-PasswordRecoveryPanel", "");
                WebControlAdapterExtender.WriteImage(writer, login.PasswordRecoveryIconUrl, "Password recovery");
                WebControlAdapterExtender.WriteLink(writer, login.HyperLinkStyle.CssClass, Extender.ResolveUrl(login.PasswordRecoveryUrl), "Password recovery", login.PasswordRecoveryText);
                WebControlAdapterExtender.WriteEndDiv(writer);
            }
        }
Jul 18, 2007 at 7:25 PM
One thing to add. You may need to wrap the IconUrl variables in Extender.ResolveUrl() as well so that icons for the links, when used, show up correctly to the user.
Coordinator
Jul 20, 2007 at 11:31 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.