Search code examples
.netuser-controlsumbraco

.NET imagebutton - does it require codebehind?


I've created a simple .NET usercontrol for logging into a members area on a website (the site is powered by Umbraco and uses their membership provider).

It worked fine until I changed the submit button on the log-in usercontrol to an imagebutton. Now it doesn't seem to submit anything - it just reloads the page when clicked and doesn't log the user in.

At the moment, the control is just being inserted as a standard .aspx usercontrol, without being compiled into a DLL - which worked with the standard submit button but doesn't with the imagebutton. I'm thinking that to get an imagebutton working requires a code-behind page, hence I need to compile it. Is this right?

I'm a total noob at .NET as you can probably tell, so any advice would be great.

Here's the code I have now:

<%@ Control Language="C#" AutoEventWireup="true" %>
<asp:Login ID="Login1" runat="server">
    <LayoutTemplate>
        <fieldset>
            <legend>Log in details</legend>
            <div>
                <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                <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="ctl00$Login1">*</asp:RequiredFieldValidator>
            </div>
            <div>
                <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                    ControlToValidate="Password" ErrorMessage="Password is required." 
                    ToolTip="Password is required." ValidationGroup="ctl00$Login1">*</asp:RequiredFieldValidator>
            </div>
            <div>
                <asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
            </div>
            <div>
                <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
            </div>
        </fieldset>

        <asp:ImageButton ID="LoginButton" runat="server" src="~/css/img/btn_log-in.png" CssClass="rollover" ValidationGroup="ctl00$Login1" />

        <br />
        <br />
        <div style="background: #fc0">STATUS (to be removed) <asp:LoginStatus ID="LoginStatus1" LoginText="Log in or register" LogoutText="Log out" runat="server" /></div>
    </LayoutTemplate>
</asp:Login>

The only thing different in the version which worked was that insead of the <asp:ImageButton... it had this:

<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="ctl00$Login1" />

Solution

  • Simply speaking, you need to recompile the DLL.

    The reason being that there is a pagename.designer.cs file which gets updated when you change a control in the markup and that is a code file which would only update upon recompilation.