.NET ------ TextBox设置密码格式,通过按钮切换是否显示密码

页面展示:

点击按钮密码展示,图片切换,再点击密码隐藏图片切换

 

 实现:

1、页面

    <asp:TextBox MaxLength="24"  ID="tbWebSite_UserPwd1" runat="server" TextMode="Password"></asp:TextBox>

    <asp:ImageButton runat="server" ID="btnShowClose" BorderWidth="0" ImageUrl="~/qdAdmin/qdimages/yanjing_xianshi.png" OnClick="btnShowClose_Click"/>

2、后面方法

复制代码
  protected void btnShowClose_Click(object sender, EventArgs e)
    {
        //记住密码
        this.tbWebSite_UserPwd1.Attributes.Add("value", this.tbWebSite_UserPwd1.Text);
        this.tbWebSite_UserPwd2.Attributes.Add("value", this.tbWebSite_UserPwd2.Text);
        ImageButton btn = (ImageButton)sender;
        if (btn.ID == "btnShowClose")
        {
 
            if (tbWebSite_UserPwd1.TextMode == TextBoxMode.Password)
            {
                //密码显示 与切换图片
                tbWebSite_UserPwd1.TextMode = TextBoxMode.SingleLine;
                btnShowClose.ImageUrl = "~/qdAdmin/qdimages/yanjing_yincang.png";
            }
            else
            {
                tbWebSite_UserPwd1.TextMode = TextBoxMode.Password;
                btnShowClose.ImageUrl = "~/qdAdmin/qdimages/yanjing_xianshi.png";
            }

        }else if (btn.ID == "btnShowClose2")
        {
           
            if (tbWebSite_UserPwd2.TextMode == TextBoxMode.Password)
            {
                tbWebSite_UserPwd2.TextMode = TextBoxMode.SingleLine;
                btnShowClose2.ImageUrl = "~/qdAdmin/qdimages/yanjing_yincang.png";
            }
            else
            {
                tbWebSite_UserPwd2.TextMode = TextBoxMode.Password;
                btnShowClose2.ImageUrl = "~/qdAdmin/qdimages/yanjing_xianshi.png";
            }
        }
    }
复制代码

 

posted on   obge  阅读(442)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示