string logname = txtLogName.Text.Trim();
string pwd = DB.EncryptPassword(txtPwd.Text, "MD5");
string pwdAgain = DB.EncryptPassword(txtPwdAgain.Text, "MD5");
string username = txtUserName.Text.Trim();
string dpm = dplDep.SelectedValue.ToString();
string job = txtJob.Text.ToString();
string tel = txtTel.Text.ToString().Trim();
string pruid = dplPru.SelectedValue.ToString();
string bz = txtRmk.Text; using (SqlConnection con = DB.getstrConn())
{
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "proc_InsertUserInfo";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@logname",SqlDbType.NVarChar,500).Value=logname;
cmd.Parameters.Add("@username",SqlDbType.NVarChar,500).Value=username;
cmd.Parameters.Add("@pwd", SqlDbType.NVarChar, 500).Value = pwd;
cmd.Parameters.Add("@bm",SqlDbType.NVarChar,500).Value=dpm;
请问该如何取值啊
string pwd = DB.EncryptPassword(txtPwd.Text, "MD5");
string pwdAgain = DB.EncryptPassword(txtPwdAgain.Text, "MD5");
string username = txtUserName.Text.Trim();
string dpm = dplDep.SelectedValue.ToString();
string job = txtJob.Text.ToString();
string tel = txtTel.Text.ToString().Trim();
string pruid = dplPru.SelectedValue.ToString();
string bz = txtRmk.Text; using (SqlConnection con = DB.getstrConn())
{
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "proc_InsertUserInfo";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@logname",SqlDbType.NVarChar,500).Value=logname;
cmd.Parameters.Add("@username",SqlDbType.NVarChar,500).Value=username;
cmd.Parameters.Add("@pwd", SqlDbType.NVarChar, 500).Value = pwd;
cmd.Parameters.Add("@bm",SqlDbType.NVarChar,500).Value=dpm;
请问该如何取值啊
<p>
<asp:TextBox TextMode="Password" runat="server" ID="password1" />
</p>
<p>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</p>
protected void Button1_Click(object sender, EventArgs e)
{
string tt = password1.Text;
Response.Write(tt);
}可以获取到值。
前台:
<asp:Panel ID="Panel1" runat="server">
<table cellspacing="5"cellpadding="5" style="margin:0px;padding:0px;" align="center">
<tr>
<td style="width:100px;height:20px;">
密 码:</td>
<td style="width:100px;height:20px;">
<asp:TextBox ID="txtPwd" runat="server" TextMode="Password"></asp:TextBox>
</td>
<td style="width:100px;height:20px;" align="left">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
Display="Dynamic" ErrorMessage="请输入密码" ControlToValidate="txtPwd"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="width:100px;height:20px;">
确认密码:</td>
<td style="width:100px;height:20px;">
<asp:TextBox ID="txtPwdAgain" runat="server" TextMode="Password"></asp:TextBox>
</td>
<td style="width:100px;height:20px;" align="left">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtPwdAgain" Display="Dynamic" ErrorMessage="请再次输入密码"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txtPwd" ControlToValidate="txtPwdAgain" Display="Dynamic"
ErrorMessage="两次输入密码不同!">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnNext" runat="server" Text="下一步" onclick="btnNext_Click" />
</td>
<td>
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel ID="Panel2" runat="server">
<table align="center" cellpadding="5" cellspacing="5"
style="margin:0px;padding:0px;">
<tr>
<td colspan="3" class="style1">
用户信息</td>
</tr>
<tr>
<td style="width:100px;height:20px;">
用户姓名:</td>
<td style="width:100px;height:20px;">
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</td>
<td align="left" style="width:200px;height:20px;">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtUserName" ErrorMessage="请输入用户姓名"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<tr>
<td style="width:100px;height:100px;">
备 注:</td>
<td style="width:100px;height:100px;">
<asp:TextBox ID="txtRmk" runat="server"
TextMode="MultiLine" Height="100"></asp:TextBox>
</td>
<td align="left" style="width:100px;height:20px;">
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnReg" runat="server"
Text="注册" onclick="btnReg_Click" />
</td>
<td>
</td>
</tr>
</table>
</asp:Panel>
后台:public partial class User_UserReg : System.Web.UI.Page
{
database DB = new database();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ DplistDep();
DplistClass();
Panel1.Visible = true;
Panel2.Visible = false; }
}
protected void btnNext_Click(object sender, EventArgs e)
{
Panel1.Visible = false;
Panel2.Visible = true;
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
using (SqlConnection con = DB.getstrConn())
{
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
string logname = args.Value;
cmd.CommandText = "select Count(*) from UserInfo where logname='"+logname+"'";
int count=Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{ //count>0表示用户存在,不通过验证
args.IsValid = false; }
else
{ args.IsValid = true;
} }
}
}
protected void btnReg_Click(object sender, EventArgs e)
{
string logname = this.txtLogName.Text.Trim();
string pwd = this.DB.EncryptPassword(this.txtPwd.Text, "MD5");
string pwdAgain = this.DB.EncryptPassword(this.txtPwdAgain.Text, "MD5");
string username = this.txtUserName.Text.Trim();
string dpm = this.dplDep.SelectedValue.ToString();
string job = this.txtJob.Text.ToString();
string tel = this.txtTel.Text.ToString().Trim();
string pruid = this.dplPru.SelectedValue.ToString();
string bz = this.txtRmk.Text; using (SqlConnection con = DB.getstrConn())
{
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "proc_InsertUserInfo";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@logname",SqlDbType.NVarChar,500).Value=logname;
cmd.Parameters.Add("@username",SqlDbType.NVarChar,500).Value=username;
cmd.Parameters.Add("@pwd", SqlDbType.NVarChar, 500).Value = pwd;
cmd.Parameters.Add("@bm",SqlDbType.NVarChar,500).Value=dpm;
cmd.Parameters.Add("@zw",SqlDbType.NVarChar,500).Value=job;
cmd.Parameters.Add("@phone",SqlDbType.NVarChar,500).Value=tel;
cmd.Parameters.Add("@pruid", SqlDbType.NVarChar, 500).Value = pruid;
cmd.Parameters.Add("@bz", SqlDbType.NVarChar, 500).Value = bz;
if (pwd == pwdAgain)
{
cmd.ExecuteNonQuery();
Response.Write(pwd);
Response.Write("<script>alert('插入成功!')</script>");
}
else
{ Response.Write("<script>alert('插入失败!')</script>"); }
}
}
类:
public string EncryptPassword(string password, string passwordformate)
{
string encryptpassword;
if (passwordformate == "SHA1 ")
encryptpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "SHA1 ");
else if (passwordformate == "MD5 ")
encryptpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5 ");
else
encryptpassword = " ";
return encryptpassword;
}
我后来看了下,好像密码框的值和panel隐藏有关系,panel1隐藏后密码框取值就成了空的了
txtPwdAgain.Text = "xxxxxxxxxx";
这样是不行的。
只能
txtPwdAgain.Attributes.Add("value","xxxx");
进行赋值,明白了吧?