Skip to main content
 首页 » 编程设计

c#之类、结构或接口(interface)成员声明中的无效标记 ';'

2024年02月05日12shangdawei

我正在尝试使用 Web 控件在 ASP.NET 网络表单中创建用户登录表单。编译代码时,我在设计器类中遇到此错误。登录表单的代码如下:

<form class="cd-form"> 
    <p class="fieldset"> 
        <label class="image-replace cd-email" for="signin-email">Username</label> 
        <asp:TextBox class="full-width has-padding has-border" ID="signin-email" type="email" placeholder="E-mail" runat="server"></asp:TextBox> 
        <span class="cd-error-message">Error message here!</span> 
    </p> 
 
    <p class="fieldset"> 
        <label class="image-replace cd-password" for="signin-password">Password</label> 
        <asp:TextBox class="full-width has-padding has-border" ID="signin-password" type="text" placeholder="Password" runat="server"></asp:TextBox> 
        <a href="#0" class="hide-password">Hide</a> 
        <span class="cd-error-message">Error message here!</span> 
    </p> 
 
    <p class="fieldset"> 
        <input type="checkbox" id="remember-me" checked> 
        <label for="remember-me">Remember me</label> 
    </p> 
 
    <p class="fieldset"> 
      <asp:Button ID="btn_login" runat="server" value="Login" OnClick="btn_login_Click1" /> 
    </p> 
</form> 

为什么会出现此错误?

编辑:

这是设计器代码

public partial class main { 
 
        /// <summary> 
        /// signin-email control. 
        /// </summary> 
        /// <remarks> 
        /// Auto-generated field. 
        /// To modify move field declaration from designer file to code-behind file. 
        /// </remarks> 
        protected global::System.Web.UI.WebControls.TextBox signin-email; 
 
        /// <summary> 
        /// signin-password control. 
        /// </summary> 
        /// <remarks> 
        /// Auto-generated field. 
        /// To modify move field declaration from designer file to code-behind file. 
        /// </remarks> 
        protected global::System.Web.UI.WebControls.TextBox signin-password; 
 
        /// <summary> 
        /// btn_login control. 
        /// </summary> 
        /// <remarks> 
        /// Auto-generated field. 
        /// To modify move field declaration from designer file to code-behind file. 
        /// </remarks> 
        protected global::System.Web.UI.WebControls.Button btn_login; 
    } 

请您参考如下方法:

在 C# 中不允许在变量名中使用破折号。例如,您可以通过将 signin-email 指定为 asp:TextBox 的 ID 来实现。自动生成的代码将在 C# 代码中使用这些值。

重命名字段以使用下划线,而不是破折号。