怎么获取密码框的值

ljm19891118 2010-06-16 08:40:35

<asp:TextBox ID="pwd" runat="server" TextMode="Password"></asp:TextBox>


刚在做的时候获取的值始终都是空的
百度了下
知道密码框自动隐藏了
...全文
520 21 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuangbaojun 2010-06-16
  • 打赏
  • 举报
回复
LZ,我刚试过没有什么问题,就是this.pwd就可以获取了,在后台添加一个onclick事件就可以了!
ljm19891118 2010-06-16
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 wuyq11 的回复:]
CustomValidator1_ServerValidate回传时密码丢失
使用ajax判断
[/Quote]

嗯 谢谢
找出原因了
我在去研究研究
ljm19891118 2010-06-16
  • 打赏
  • 举报
回复
以上就是全部的代码了
页面的zhuce.aspx
zhuce.cs
还有个连接数据库的
ljm.cs

上面的密码框是SingleLine类型的可以读取但是换成密码类型的 读取就为空
ljm19891118 2010-06-16
  • 打赏
  • 举报
回复


<asp:Panel ID="Panel2" runat="server" Height="400px" Width="680px">
<table border="1">
<tr>
<td align="center" colspan="4">
请填写下列个人信息</td>
</tr>
<tr>
<td style="width: 709px; height: 26px">
真实姓名:</td>
<td style="width: 100px; height: 26px">
<asp:TextBox ID="zsname" runat="server"></asp:TextBox></td>
<td class="style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="zsname" ErrorMessage="姓名不能为空" Width="100px"></asp:RequiredFieldValidator>
</td>
<td rowspan="6" class="style4">
<asp:Image ID="Image1" runat="server" Height="208px" Width="184px" /></td>
</tr>
<tr>
<td style="width: 709px; height: 13px">
性别:</td>
<td  style="width: 100px; height: 13px">
<asp:RadioButtonList ID="sex" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
</asp:RadioButtonList></td>
<td class="style2">
</td>
</tr>
<tr>
<td style="width: 709px; height: 21px">
出生日期:</td>
<td style="width: 100px; height: 21px">
<asp:TextBox ID="birthday" runat="server"></asp:TextBox></td>
<td class="style3">
</td>
</tr>
<tr>
<td style="width: 709px; height: 21px">
省份:</td>
<td style="width: 100px; height: 21px">
<asp:DropDownList ID="province" runat="server">
<asp:ListItem>湖北</asp:ListItem>
<asp:ListItem>河北</asp:ListItem>
</asp:DropDownList></td>
<td class="style3">
</td>
</tr>
<tr>
<td style="width: 709px; height: 21px">
城市:</td>
<td style="width: 100px; height: 21px">
<asp:DropDownList ID="city" runat="server">
<asp:ListItem>武汉</asp:ListItem>
<asp:ListItem>咸宁</asp:ListItem>
<asp:ListItem>汉川</asp:ListItem>
</asp:DropDownList></td>
<td class="style3">
</td>
</tr>
<tr>
<td style="width: 709px; height: 13px">
教育程度:</td>
<td style="width: 100px; height: 13px">
<asp:DropDownList ID="jiaoyu" runat="server">
<asp:ListItem>高中</asp:ListItem>
<asp:ListItem>本科</asp:ListItem>
<asp:ListItem>专科</asp:ListItem>
<asp:ListItem>硕士</asp:ListItem>
</asp:DropDownList></td>
<td class="style2">
</td>
</tr>
<tr>
<td style="width: 709px; height: 13px">
月收入:</td>
<td style="width: 100px; height: 13px">
<asp:DropDownList ID="shouru" runat="server">
<asp:ListItem>1000以上</asp:ListItem>
<asp:ListItem>5000以上</asp:ListItem>
<asp:ListItem>3000以上</asp:ListItem>
</asp:DropDownList></td>
<td class="style2">
</td>
<td class="style5">
 <asp:Button ID="Button3" runat="server" Text="加载" OnClick="Button3_Click" /> 
<asp:FileUpload ID="FileUpload1" runat="server" EnableTheming="True" Width="56px" /></td>
</tr>
<tr>
<td style="width: 709px; height: 11px">
兴趣爱好:</td>
<td style="height: 11px" colspan="3" align="left">
<asp:CheckBoxList ID="aihao" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>三国杀</asp:ListItem>
<asp:ListItem>DNF</asp:ListItem>
</asp:CheckBoxList></td>
</tr>
<tr>
<td colspan="4" style="height: 14px" align="center">
  
<asp:Button ID="Button5" runat="server" Text="下一步" OnClick="Button5_Click" /></td>
</tr>
</table>
</asp:Panel>
<br />
<br />
<br />
<br />
<br />
<asp:Panel ID="Panel4" runat="server" Height="197px" Width="684px">
<table border="1" style="width: 680px">
<tr>
<td align="center" colspan="3">
填写联系方式</td>
</tr>
<tr>
<td style="width: 269px; height: 25px" align="right">
邮政编码:</td>
<td style="width: 154px; height: 25px">
<asp:TextBox ID="youbian" runat="server"></asp:TextBox></td>
<td style="width: 458px; height: 25px" align="left">
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator"
ValidationExpression="\d{6}" ControlToValidate="youbian"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td style="width: 269px; height: 21px" align="right">
身份证号:</td>
<td style="width: 154px; height: 21px">
<asp:TextBox ID="shenfen" runat="server"></asp:TextBox></td>
<td style="width: 458px; height: 21px" align="left">
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="RegularExpressionValidator" ControlToValidate="shenfen" ValidationExpression="\d{17}[\d|X]|\d{15}"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td style="width: 269px; height: 26px" align="right">
家庭住址:</td>
<td style="width: 154px; height: 26px">
<asp:TextBox ID="address" runat="server"></asp:TextBox></td>
<td style="width: 458px; height: 26px">
</td>
</tr>
<tr>
<td style="width: 269px; height: 12px" align="right">
Email:</td>
<td style="width: 154px; height: 12px">
<asp:TextBox ID="email" runat="server"></asp:TextBox></td>
<td style="width: 458px; height: 12px" align="left">
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="RegularExpressionValidator"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="email"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td align="center" colspan="3" style="height: 24px">
<asp:Button ID="Button6" runat="server" Text="完成" OnClick="Button6_Click" /></td>
</tr>
</table>
</asp:Panel>

</center>
</div>
</form>
</body>
</html>

wuyq11 2010-06-16
  • 打赏
  • 举报
回复
CustomValidator1_ServerValidate回传时密码丢失
使用ajax判断
ljm19891118 2010-06-16
  • 打赏
  • 举报
回复
页面代码分2楼


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="zhuce.aspx.cs" Inherits="zhuce" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.style1
{
height: 26px;
width: 877px;
}
.style2
{
height: 13px;
width: 877px;
}
.style3
{
height: 21px;
width: 877px;
}
.style4
{
width: 191px;
}
.style5
{
height: 13px;
width: 191px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div >
<center>
  
<asp:Panel ID="Panel3" runat="server" Height="168px" Width="672px">
<table border="1" >
<tr>
<td align="center" style="width: 656px; height: 46px">
用户协议</td>
</tr>
<tr>
<td style="width: 656px; height: 103px">
  <br />
  无聊的人啊@<br />
</td>
</tr>
<tr>
<td style="width: 656px; height: 7px" align="center">
<br />

<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal"
AutoPostBack="True"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged1" >
<asp:ListItem Value="1">同意</asp:ListItem>
<asp:ListItem Value="0">不同意</asp:ListItem>

</asp:RadioButtonList></td>
</tr>


<tr>
<td style="width: 656px; height: 56px" align="center">
<asp:Button ID="Button1" runat="server" Text="下一步" OnClick="Button1_Click1" /></td>
</tr>
</table>
</asp:Panel>
<br />
<br />
<br />
<br />
 
   <br />



 
<asp:Panel ID="Panel1" runat="server" Height="184px" Width="680px">
<table border="1">
<tr>
<td align="center" colspan="2" style="height: 55px">
登录信息</td>
</tr>
<tr>
<td align="right" style="width: 418px; height: 21px">
用户名:</td>
<td style="width: 634px; height: 21px" align="left">
<asp:TextBox ID="username" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="username"
OnServerValidate="CustomValidator1_ServerValidate">用户已经存在</asp:CustomValidator></td>
</tr>
<tr>
<td align="right" style="width: 418px; height: 26px">
密码:</td>
<td align="left" style="width: 634px; height: 26px">
<asp:TextBox ID="pwd" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 418px">
重复密码:</td>
<td style="width: 634px" align="left">
<asp:TextBox ID="rpwd" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="输入的密码不一致" ControlToCompare="pwd" ControlToValidate="rpwd"></asp:CompareValidator></td>
</tr>
<tr>
<td colspan="2" style="height: 22px" align="center">
<asp:Button ID="Button2" runat="server" Text="下一步" OnClick="Button2_Click" /></td>
</tr>
</table>
</asp:Panel>
<br />
<br />
<br />
<br />
<br />

ljm19891118 2010-06-16
  • 打赏
  • 举报
回复
App_code/ljm.cs


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// ljm 的摘要说明
/// </summary>
public class ljm
{
public ljm()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static SqlConnection createCon()
{
return new SqlConnection("server=(local);uid=sa;pwd=123456;database=ljm;");
}
public static bool panduan(string userName)
{
SqlConnection con = ljm.createCon();
con.Open();
SqlCommand cmd =new SqlCommand("select count(*) from xinxi where 用户名='" + userName + "'", con);
int i = (int)cmd.ExecuteScalar();
con.Close();
if (i > 0)
return true;
else
return false;

}


}

ljm19891118 2010-06-16
  • 打赏
  • 举报
回复
在写入数据库的上面几行
生活的信仰 2010-06-16
  • 打赏
  • 举报
回复
关注中。。
ljm19891118 2010-06-16
  • 打赏
  • 举报
回复

我做的是上课的实验内容
代码很多
谢谢了






using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class zhuce : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Panel3.Visible = true;
this.Panel1.Visible = false;
this.Panel2.Visible = false;
this.Panel4.Visible = false;
Button1.Enabled = false;
// this.pwd.Attributes.Add("value", Request["pwd"]);

}
}

protected void Button3_Click(object sender, EventArgs e)
{
FileUpload1.PostedFile.SaveAs(Server.MapPath("upFile") + "\\" + FileUpload1.FileName);
Image1.ImageUrl = "upFile\\" + FileUpload1.FileName;


}




protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (ljm.panduan(username.Text))
{
CustomValidator1.IsValid =false;

}
else
{
CustomValidator1.IsValid = true;
}

}

protected void Button1_Click1(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue == "1")
{
this.Panel3.Visible = false;
this.Panel1.Visible = true;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (ljm.panduan(username.Text))
{
CustomValidator1.IsValid = false;

}
else
{
CustomValidator1.IsValid = true;
}


if (CustomValidator1.IsValid)
{
this.Panel1.Visible = false;
this.Panel2.Visible = true;

}
else
{
// Response.Write("<script lanuage=javascript>alert('用户名存在!!!')</script>");
pwd.Text = "";
rpwd.Text = "";
SetFocus(username);

}
}




protected void Button5_Click(object sender, EventArgs e)
{
this.Panel2.Visible = false;
this.Panel4.Visible = true;
}
protected void Button6_Click(object sender, EventArgs e)
{
try
{

String userid1 = username.Text;
String mima =pwd.Text ;
String name = zsname.Text;
String birthday1 = birthday.Text;
String sex1 = sex.SelectedValue;
String province1 = province.Text;
String city1 = city.Text;
String jiaoyu1 = jiaoyu.Text;

String aihao1 = "";
foreach (ListItem i in aihao.Items)
{
if (i.Selected)
aihao1 += " " + i;
}
String shouru1 = shouru.Text;

String img = Image1.ImageUrl.ToString();
String email1 = email.Text;
String youbian1 = youbian.Text;
String shenfen1 = shenfen.Text;
String dizhi = address.Text;




SqlConnection con = ljm.createCon();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert xinxi(用户名,密码,真实姓名,性别,省份,城市,教育程度,爱好,月收入,图像,邮编,身份证号,地址,email)values('" + userid1 + "','" +mima+ "','" + name + "','" + sex1 + "','" + province1 + "','" + city1 + "','" + jiaoyu1 + "','" + aihao1 + "','" + shouru1 + "','" + img + "','" + youbian1 + "','" + shenfen1 + "','" + dizhi + "','" + email1 + "')";
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
// Response.Redirect("success.aspx");
Response.Write(pwd.Text);
}
catch (SqlException) { Response.Write("<script>alert('注册错误!')</script>"); };



}

protected void RadioButtonList1_SelectedIndexChanged1(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue == "1")
{
Button1.Enabled = true;
}
if (RadioButtonList1.SelectedValue == "0")
{
Button1.Enabled = false;
}
}
}

wuyq11 2010-06-16
  • 打赏
  • 举报
回复
贴出代码看看
ljm19891118 2010-06-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wuyq11 的回复:]
赋值使用pwd.Attributes.Add("value","");
[/Quote]

谢谢了

在密码框里面输入了值
怎么获取


当我设置文本框的属性为Password
我用pwd.text获取的始终都是空
当我设置的是SingleLine
则可以获取
wuyq11 2010-06-16
  • 打赏
  • 举报
回复
赋值使用pwd.Attributes.Add("value","");
ljm19891118 2010-06-16
  • 打赏
  • 举报
回复
我把文本框的属性
从这Password换成SingleLine
就可以获取了
用品password获取的始终都是空
ljm19891118 2010-06-16
  • 打赏
  • 举报
回复
刚从jsp转.net
就发现这问题了
ljm19891118 2010-06-16
  • 打赏
  • 举报
回复
在写注册页面的时候
获取密码
获取的值都是空....
wuyq11 2010-06-16
  • 打赏
  • 举报
回复
是否赋值了
马老虎 2010-06-16
  • 打赏
  • 举报
回复
[Quote=引用楼主 ljm19891118 的回复:]
HTML code

<asp:TextBox ID="pwd" runat="server" TextMode="Password"></asp:TextBox>


刚在做的时候获取的值始终都是空的
百度了下
知道密码框自动隐藏了

[/Quote]
可以获得啊。
一定是你取值又问题
ljm19891118 2010-06-16
  • 打赏
  • 举报
回复
pwd.text
获得的是空的
stepday 2010-06-16
  • 打赏
  • 举报
回复
this.pwd.Text就可以获取到了的
加载更多回复(1)

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧