2010-07-29 68 views
0

我创建了一个简单的.NET用户控件,用于登录网站上的会员区(该网站由Umbraco提供支持并使用其会员提供商)。.NET imagebutton - 它需要隐藏代码吗?

它工作正常,直到我将登录用户控件上的提交按钮更改为imagebutton。现在它似乎没有提交任何内容 - 它只是在点击时重新加载页面,并且不会登录用户。

此刻,控件只是作为标准.aspx用户控件插入,而未被编译到一个DLL中 - 它与标准提交按钮一起工作,但不与imagebutton一起使用。我在想,要得到一个imagebutton的工作需要一个代码隐藏页面,因此我需要编译它。这是正确的吗?

我是一个.NET的总noob,因为你可以告诉,所以任何建议都会很好。

下面的代码我现在有:

<%@ 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> 

在版本唯一不同的这工作是,<asp:ImageButton的INSEAD ......它有这样的:

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

你可以发布你的“之前”和“之后”的代码。这将有助于诊断问题。 – ChrisF 2010-07-29 14:22:35

回答

0

简而言之,您需要重新编译该DLL。
原因是有一个pagename.designer.cs文件在更改标记中的控件时得到更新,并且该代码文件仅在重新编译时才会更新。

HTH!

+0

感谢Dienekes。所以为了澄清我需要编译成DLL?我不能只运行这个.aspx页面? – Dan 2010-08-03 06:38:46

0

如果你只将标记从<asp:linkbutton更改为<asp:imagebutton然后是它将失败,因为在编译后的dll中,控件仍然是LinkBut​​ton。

它不需要代码隐藏,但ofcourse .NET做的东西来处理控件,当你改变控件的类型时需要你重新编译。

LinkBut​​ton和ImageButton的Click事件签名是不同的。

+0

对不起,我没有真正关注。没有编译的DLL,因为它只是一个基本的用户控件。在umbraco中,你只需上传.aspx,所以不需要编译成DLL。至少没有当它是一个标准的提交按钮 Dan 2010-07-29 14:51:31

0

你的代码有一些不同 - 使用:

CommandName="Login"

希望这会有所帮助。