C# asp更改密码控件自定义

C# asp更改密码控件自定义,c#,asp.net,controls,C#,Asp.net,Controls,有没有办法自定义ASP changepassword控件中的文本框 <asp:ChangePassword id="myChangePassword" newpasswordregularexpressionerrormessage="Error: Your password must be at least 5 characters long, and contain at least one number and one special character." runat="serv

有没有办法自定义ASP changepassword控件中的文本框

<asp:ChangePassword id="myChangePassword" newpasswordregularexpressionerrormessage="Error: Your password must be at least 5 characters long, and contain at least one number and one special character." 
runat="server"  OnChangingPassword="ChangingPassword" 
OnChangedPassword="ChangedPassword" OnCancelButtonClick="CancelClick"></asp:ChangePassword>

例如,我希望顶部字段显示当前密码,而不仅仅是密码,这可能吗

谢谢

是在asp.net中自定义控件的好教程。

是在asp.net中自定义控件的好教程。


<asp:ChangePassword ID="ChangePassword1" runat="server" 
    PasswordLabelText="Current Password:">
</asp:ChangePassword>
这就是你想要的吗?



这就是你想要的吗?

是的,这是可能的。与许多asp.net控件一样,控件内部有一个标记,允许您自定义字段

看看这个:

<asp:ChangePassword ID="ChangePassword1" runat="server" 
        ContinueDestinationPageUrl="~/Users/UserProfile.aspx" style="margin-right: 2px" 
        Width="450px">
        <ChangePasswordTemplate>
            <table cellpadding="1" cellspacing="0" style="border-collapse:collapse;">
                <tr>
                    <td>
                        <table cellpadding="0">
                            <tr>
                                <td align="center" colspan="2">
                                    Change Your Password</td>
                            </tr>
                            <tr>
                                <td align="left">
                                    <asp:Label ID="CurrentPasswordLabel" runat="server" 
                                        AssociatedControlID="CurrentPassword">Password</asp:Label>
                                </td>
                                <td style="width: 166px">
                                    <asp:TextBox ID="CurrentPassword" runat="server" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="CurrentPasswordRequired" runat="server" 
                                        ControlToValidate="CurrentPassword" ErrorMessage="Password is required." 
                                        ToolTip="Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="left">
                                    <asp:Label ID="NewPasswordLabel" runat="server" 
                                        AssociatedControlID="NewPassword">New Password</asp:Label>
                                </td>
                                <td style="width: 166px">
                                    <asp:TextBox ID="NewPassword" runat="server" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="NewPasswordRequired" runat="server" 
                                        ControlToValidate="NewPassword" ErrorMessage="New Password is required." 
                                        ToolTip="New Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="left">
                                    <asp:Label ID="ConfirmNewPasswordLabel" runat="server" 
                                        AssociatedControlID="ConfirmNewPassword">Confirm New Password</asp:Label>
                                </td>
                                <td style="width: 166px">
                                    <asp:TextBox ID="ConfirmNewPassword" runat="server" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="ConfirmNewPasswordRequired" runat="server" 
                                        ControlToValidate="ConfirmNewPassword" 
                                        ErrorMessage="Confirm New Password is required." 
                                        ToolTip="Confirm New Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2">
                                    <asp:CompareValidator ID="NewPasswordCompare" runat="server" 
                                        ControlToCompare="NewPassword" ControlToValidate="ConfirmNewPassword" 
                                        Display="Dynamic" 
                                        ErrorMessage="The Confirm New Password must match the New Password entry." 
                                        ValidationGroup="ChangePassword1"></asp:CompareValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2" style="color:Red;">
                                    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Button ID="ChangePasswordPushButton" runat="server" 
                                        CommandName="ChangePassword" Text="Change Password" 
                                        ValidationGroup="ChangePassword1" />
                                </td>
                                <td style="width: 166px">
                                    <asp:Button ID="CancelPushButton" runat="server" CausesValidation="False" 
                                        CommandName="Cancel" Text="Cancel" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </ChangePasswordTemplate>
    </asp:ChangePassword>

。它有更多关于这些模板标记如何工作的内容

是的,这是可能的。与许多asp.net控件一样,控件内部有一个标记,允许您自定义字段

看看这个:

<asp:ChangePassword ID="ChangePassword1" runat="server" 
        ContinueDestinationPageUrl="~/Users/UserProfile.aspx" style="margin-right: 2px" 
        Width="450px">
        <ChangePasswordTemplate>
            <table cellpadding="1" cellspacing="0" style="border-collapse:collapse;">
                <tr>
                    <td>
                        <table cellpadding="0">
                            <tr>
                                <td align="center" colspan="2">
                                    Change Your Password</td>
                            </tr>
                            <tr>
                                <td align="left">
                                    <asp:Label ID="CurrentPasswordLabel" runat="server" 
                                        AssociatedControlID="CurrentPassword">Password</asp:Label>
                                </td>
                                <td style="width: 166px">
                                    <asp:TextBox ID="CurrentPassword" runat="server" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="CurrentPasswordRequired" runat="server" 
                                        ControlToValidate="CurrentPassword" ErrorMessage="Password is required." 
                                        ToolTip="Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="left">
                                    <asp:Label ID="NewPasswordLabel" runat="server" 
                                        AssociatedControlID="NewPassword">New Password</asp:Label>
                                </td>
                                <td style="width: 166px">
                                    <asp:TextBox ID="NewPassword" runat="server" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="NewPasswordRequired" runat="server" 
                                        ControlToValidate="NewPassword" ErrorMessage="New Password is required." 
                                        ToolTip="New Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="left">
                                    <asp:Label ID="ConfirmNewPasswordLabel" runat="server" 
                                        AssociatedControlID="ConfirmNewPassword">Confirm New Password</asp:Label>
                                </td>
                                <td style="width: 166px">
                                    <asp:TextBox ID="ConfirmNewPassword" runat="server" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="ConfirmNewPasswordRequired" runat="server" 
                                        ControlToValidate="ConfirmNewPassword" 
                                        ErrorMessage="Confirm New Password is required." 
                                        ToolTip="Confirm New Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2">
                                    <asp:CompareValidator ID="NewPasswordCompare" runat="server" 
                                        ControlToCompare="NewPassword" ControlToValidate="ConfirmNewPassword" 
                                        Display="Dynamic" 
                                        ErrorMessage="The Confirm New Password must match the New Password entry." 
                                        ValidationGroup="ChangePassword1"></asp:CompareValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2" style="color:Red;">
                                    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Button ID="ChangePasswordPushButton" runat="server" 
                                        CommandName="ChangePassword" Text="Change Password" 
                                        ValidationGroup="ChangePassword1" />
                                </td>
                                <td style="width: 166px">
                                    <asp:Button ID="CancelPushButton" runat="server" CausesValidation="False" 
                                        CommandName="Cancel" Text="Cancel" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </ChangePasswordTemplate>
    </asp:ChangePassword>

。它有更多关于这些模板标记如何工作的内容

Aspx代码

<div align="center">


<asp:ChangePassword ID="ChangePassword1" runat="server" BackColor="#F7F7DE" 
                BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" 
                Font-Names="Verdana" Font-Size="10pt" 
                onchangedpassword="ChangePassword1_ChangedPassword">
    <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />
</asp:ChangePassword>


        </div>
public partial class admin_Changepwd : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString);
    SqlCommand cmd;
    SqlDataReader dr;

protected void Page_Load(object sender, EventArgs e)
{

}

protected void ChangePassword1_ChangedPassword(object sender, EventArgs e)
{
    cmd = new SqlCommand("update  Admin set Password ='" + ChangePassword1.ConfirmNewPassword + "' where userid = '" + Session["userid"] + "' and Password ='" + ChangePassword1.CurrentPassword + "'", con);
    cmd.Connection.Open();
    cmd.ExecuteNonQuery();
    con.Close();

}
}

Aspx代码

<div align="center">


<asp:ChangePassword ID="ChangePassword1" runat="server" BackColor="#F7F7DE" 
                BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" 
                Font-Names="Verdana" Font-Size="10pt" 
                onchangedpassword="ChangePassword1_ChangedPassword">
    <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />
</asp:ChangePassword>


        </div>
public partial class admin_Changepwd : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString);
    SqlCommand cmd;
    SqlDataReader dr;

protected void Page_Load(object sender, EventArgs e)
{

}

protected void ChangePassword1_ChangedPassword(object sender, EventArgs e)
{
    cmd = new SqlCommand("update  Admin set Password ='" + ChangePassword1.ConfirmNewPassword + "' where userid = '" + Session["userid"] + "' and Password ='" + ChangePassword1.CurrentPassword + "'", con);
    cmd.Connection.Open();
    cmd.ExecuteNonQuery();
    con.Close();

}
}

很好的解决方案。感谢分享如何定制表单。非常好的解决方案。感谢分享如何定制表单。