我正在尝试为标准的 ASP.NET 会员系统构建一些简单的用户控件。我有一个 CreateUserWizard 控件,在提交时需要将用户添加到特定角色。
ascx 文件如下所示:
<asp:CreateUserWizard ID="CreateUserWizard2" runat="server" oncreateduser="CreateUserWizard2_CreatedUser">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizard2Step1" runat="server">
<ContentTemplate>
<div class="form-error">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</div>
<fieldset class="member-control">
<legend>Registration details</legend>
<div class="standard">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username*:</asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="text-input"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="Username is required." ToolTip="Username is required." ValidationGroup="CreateUserWizard1">Username is required.</asp:RequiredFieldValidator>
</div> ...etc
C# 代码隐藏如下所示:
namespace DocumentMembership
{
public partial class ClientRegister : System.Web.UI.UserControl
{
protected void CreateUserWizard2_CreatedUser(object sender, EventArgs e)
{
// add member to role
Roles.AddUserToRole(this.CreateUserWizard2.UserName, "Client");
但是,我收到一个构建错误消息:
'DocumentMembership.ClientRegister' does not contain a definition for 'CreateUserWizard2' and no extension method 'CreateUserWizard2' accepting a first argument of type 'DocumentMembership.ClientRegister' could be found (are you missing a using directive or an assembly reference?)
当我开始输入 Roles.AddUserToRole(this.intellisense 似乎没有提供任何有用的信息来从表单中获取用户名。
我在.NET 方面真的不是很熟练,所以很明显我做错了,但我似乎无法找到解决办法。
任何人都可以建议如何让这个工作或可能是什么问题?
谢谢!