0

我有一个 ASP.NET Web 应用程序,我想在其中自定义 createUser 向导。在用户注册工作流程中,我不是要求用户输入密码,而是以编程方式生成密码,并在加载密码时为其分配密码控制。此控件将被禁用并作为通知发送给用户。以下片段是 .aspx 和相应的 C# 代码。

 <asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password" OnLoad="GenerateRandomPassword" />


protected void GenerateRandomPassword(object sender, EventArgs e)
    {
        TextBox pwdTextBox = (TextBox)RegisterUserWizardStep.ContentTemplateContainer.FindControl("Password");

        if (pwdTextBox != null)
        {
            pwdTextBox.Text = Membership.GeneratePassword(8, 2);                
        }
    }

我已经调试了代码,可以看到密码文本框的 text 属性设置正确,但是在 UI 中没有更新。还有什么我需要做的吗?谁能告诉我是什么问题?

4

1 回答 1

1

试试这个来设置密码输入的值:

pwdTextBox.Attributes.Add("value", Membership.GeneratePassword(8, 2));
于 2013-05-21T13:53:12.380 回答