Customize control layouts for webparts


I have been trying to customize the layout of the MembershipRequestWebPart and PasswordRecoveryWebPart (ChangePassword). particularly to remove the tables that are inserted and to change where the controls are rendered on the page. From what I can see from the source code, would I be correct in saying that the WebParts have been dynamically created and the controls are rendered programatically, therefore there are no front-end sections to the webparts to use a control template for instance?

The reason I there a way of programatically using control templates, if so does anyone have an experience in this or have any pointers for me? I am totally stumped.

I also recently found an article on Control Adapters... could this be my only option?

Any guidance/pointers would be greatly appreciated. Also let me know if there is some simple way that I may have totally missed here?

Thanks for your time


Wow - talk about good timing with this question.  I actually just did exactly this for a client recently, and blogged about it yesterday.

You're correct, the web parts are dynamically created and the controls are rendered programmatically, so there are no front-end sections to the web parts.

What I ended up doing is creating the template in an ascx file and then loading that template into the control.

The blog post detailing how I did it is here:

I expect i'll add the functionality to the FBA Pack in a future release.

Brilliant, thanks for this response Chris (that was good timing),

Following the steps on your blog post I still seem to get the error "UserNameTemplate does not contain an IEditableTextControl with ID UserName for the username". Not sure where I am going wrong.
 - Have created a new class TemplateLoader.cs 
 - Adding the template by loading in into the control inside the AddPasswordRecoveryControl method as follows:

_ctlPasswordRecovery.UserNameTemplate = new TemplateLoader("/_ControlTemplates/.../PasswordRecoveryTemplate.ascx", Page);

 - I think where I may be going wrong is the ascx template? I have added the PasswordRecovery control into my ascx file as follows (not sure if this is the correct way of going about it):

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PasswordRecoveryTemplate.ascx.cs" ... %>
<asp:PasswordRecovery ID="_ctlPasswordRecovery" runat="server">
        <h1>This is a template!!!!</h1>
        <p>Forgot Your Password?</p>
        <p>Enter your User Name to receive your password.</p>
        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
        <br />
        <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
        <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
        <br />
        <asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />

Any idea?

Yeah, you only put the contents of the UserNameTemplate in the ascx file.  Remove everything else and you should be ok.

Thank you, thank you!!! Works like a charm, now to customise the rest.