views:

44

answers:

3

Hi,

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" />
A: 

If you only changed the markup from <asp:linkbutton to <asp:imagebutton then yes it's going to fail because in the compiled dll the control is still a LinkButton.

It doesn't require code-behind but ofcourse .NET does stuff to handle the control which requires you to recompile when you change the type of the control.

The Click Event signatures are different for LinkButton and ImageButton.

Jeroen
Sorry, I don't really follow. There was no compiled DLL as it was simply a basic usercontrol. In umbraco, you just upload the .aspx, so there's no need to compile to a DLL. At least there wasn't when it was a standard submit button <asp:button.I did just change the mark-up from button to imagebutton, and added a 'src' property. There is no 'onclick' property on this. Is this something I need to add manually and then create the function it calls? What should be in the function, and where should the function go (in the .aspx page)?Sorry for all the questions - just very new to this.
Dan
A: 

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.

HTH!

Dienekes
Thanks Dienekes. So to clarify I DO need to compile to a DLL? I can't just run this as a .aspx page?
Dan
A: 

Hi Chris,

There is something different in your code - the use of:

CommandName="Login"
.

Hope this helps.

codegecko