C# 正在尝试在asp.net中启用显示/隐藏功能
我正在尝试启用显示/隐藏密码功能。我正在使用C#创建一个asp.net web表单 我的代码如下:C# 正在尝试在asp.net中启用显示/隐藏功能,c#,asp.net,textbox,passwords,show-hide,C#,Asp.net,Textbox,Passwords,Show Hide,我正在尝试启用显示/隐藏密码功能。我正在使用C#创建一个asp.net web表单 我的代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class show : System.Web.UI.Page { protect
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class show : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked == false)
{
TextBox1.TextMode = TextBoxMode.Password;
}
if (CheckBox1.Checked == true)
{
TextBox1.TextMode = TextBoxMode.SingleLine;
}
}
}
在mypage.aspx上
有一个复选框的autopostback属性为true,还有一个textbox的textmode为password
预期结果是:-
选中复选框时将密码显示为文本
取消选中复选框时隐藏密码
问题是:-
此代码仅工作一次,即当再次选中或取消选中复选框时,不会执行此代码。
文本框变为空白
请尽快帮助我。您在
TextBox
中丢失了值,因为在选择更改时,页面会再次加载,您需要检查是回发还是首次加载,并设置TextBox值
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string Password = TextBox1.Text;
TextBox1.Attributes.Add("value", Password);
}
}
你的问题会解决的。我已经测试过了
希望有帮助 您在
TextBox
中丢失了值,因为在选择更改时,页面会再次加载,您需要检查是回发还是首次加载,并设置TextBox值
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string Password = TextBox1.Text;
TextBox1.Attributes.Add("value", Password);
}
}
你的问题会解决的。我已经测试过了
希望有帮助 出于安全原因,无法设置密码类型字段的文本属性。因此,更改模式后设置值的另一种方法是
if (CheckBox1.Checked == false)
{
string pass = TextBox1.Text;
TextBox1.TextMode = TextBoxMode.Password;
TextBox1.Attributes.Add("value", pass);
}
if (CheckBox1.Checked)
{
TextBox1.TextMode = TextBoxMode.SingleLine;
}
出于安全原因,无法设置密码类型字段的文本属性。因此,更改模式后设置值的另一种方法是
if (CheckBox1.Checked == false)
{
string pass = TextBox1.Text;
TextBox1.TextMode = TextBoxMode.Password;
TextBox1.Attributes.Add("value", pass);
}
if (CheckBox1.Checked)
{
TextBox1.TextMode = TextBoxMode.SingleLine;
}
完全不需要为此使用回发: 标记:
<label>Password fields are just a UI convenience:</label>
<input type="password" id="password" value="super secret password" />
<label>
<input type="checkbox" id="toggle-password" /> Toggle
</label>
:
完全不需要为此使用回发: 标记:
<label>Password fields are just a UI convenience:</label>
<input type="password" id="password" value="super secret password" />
<label>
<input type="checkbox" id="toggle-password" /> Toggle
</label>
:
显示隐藏密码
$(文档).ready(函数(){
$('show#u password')。悬停(函数show(){
//将属性更改为文本
$('#txtCurrentpassword').attr('type','text');
$('.icon').removeClass('fa-fa-eye-slash').addClass('fa-fa-eye');
},
函数(){
//将属性更改回password
$('#txtCurrentpassword').attr('type','password');
$('.icon').removeClass('fa-fa-eye').addClass('fa-fa-eye-slash');
});
//复选框显示密码
$('#ShowPassword')。单击(函数(){
$('#Password').attr('type',$(this).is(':checked')?'text':'Password');
});
});
$(文档).ready(函数(){
$('#show_password1')。悬停(函数show(){
//将属性更改为文本
$('#txtNewPassword').attr('type','text');
$('.icon').removeClass('fa-fa-eye-slash').addClass('fa-fa-eye');
},
函数(){
//将属性更改回password
$('#txtNewPassword').attr('type','password');
$('.icon').removeClass('fa-fa-eye').addClass('fa-fa-eye-slash');
});
//复选框显示密码
$('#ShowPassword')。单击(函数(){
$('#Password').attr('type',$(this).is(':checked')?'text':'Password');
});
});
$(文档).ready(函数(){
$('#show_password2')。悬停(函数show(){
//将属性更改为文本
$('#txtConfirmPassword').attr('type','text');
$('.icon').removeClass('fa-fa-eye-slash').addClass('fa-fa-eye');
},
函数(){
//将属性更改回password
$('#txtConfirmPassword').attr('type','password');
$('.icon').removeClass('fa-fa-eye').addClass('fa-fa-eye-slash');
});
//复选框显示密码
$('#ShowPassword')。单击(函数(){
$('#Password').attr('type',$(this).is(':checked')?'text':'Password');
});
});
更新密码
(至少10个字符,包括1个上字符、1个下字符、1个数字和1个特殊字符)
用户名
当前密码
新密码
重新输入密码:
改变
重置
显示隐藏密码
$(文档).ready(函数(){
$('show#u password')。悬停(函数show(){
//将属性更改为文本
$('#txtCurrentpassword').attr('type','text');
$('.icon').removeClass('fa-fa-eye-slash').addClass('fa-fa-eye');
},
函数()