Search code examples
asp.netwebformschange-password

ChangePassword Control Ignores Custom Template and Renders Default


In some old code I recently came across a ChangePassword control which was rendering strangely. Despite having a bootstrap layout, it was rendering inside a single table with no layout at all.

<asp:ChangePassword
    ID="ChangePassword3"
    runat="server">
    <ChangePasswordTemplate>
        <div class="form-row">
            <div class="col-sm-6">
                <asp:Label ID="Label1" runat="server" AssociatedControlID="CurrentPassword">Current Password:</asp:Label>
            </div>
            <div class="col-sm-6">
                <asp:TextBox ID="CurrentPassword" runat="server" TextMode="Password" />
            </div>
        </div>
        <div class="form-row">
            <div class="col-sm-6">
                <asp:Label ID="NewPasswordLabel" runat="server" AssociatedControlID="NewPassword">New Password:</asp:Label>
            </div>
            <div class="col-sm-6">
                <asp:TextBox ID="NewPassword" runat="server" TextMode="Password" />
                <%=TestMessage%>
            </div>
        </div>
        <div class="form-row">
            <div class="col-sm-6">
                <asp:Label ID="ConfirmNewPasswordLabel" runat="server" AssociatedControlID="ConfirmNewPassword">Confirm New Password:</asp:Label>
            </div>
            <div class="col-sm-6">
                <asp:TextBox ID="ConfirmNewPassword" runat="server" TextMode="Password"></asp:TextBox>
            </div>
        </div>
    </ChangePasswordTemplate>
</asp:ChangePassword>

Why is it rendering incorrectly?


Solution

  • It turns out that one is unable to use a Code Render Block within this template without breaking it. However it breaks silently with no indication of error and then reverts back to the default render. Removing the following line solved the problem.

    <%=TestMessage%>