因为txtPassword的TextMode="Password",不能直接赋值
所有就用了下面的这段代码,可是也没有用,请高手帮忙:
 
          String hiddenName = "MyHiddenField";
            String hiddenValue = "111";            String csname = "ConcatScript";
            Type cstype = this.GetType();            ClientScriptManager cs = Page.ClientScript;
            cs.RegisterHiddenField(hiddenName, hiddenValue);            if (!cs.IsStartupScriptRegistered(cstype, csname))
            {
                System.Text.StringBuilder cstext = new StringBuilder();
                cstext.Append("<script type=text/javascript> function DoClick() {");
                cstext.Append("document.getElementById('txtPassword').value='" + hiddenValue + "';");
                cstext.Append("form1.txtRePassword.value='" + hiddenValue + "';} </");
                cstext.Append("script>");
                cs.RegisterStartupScript(cstype, csname, cstext.ToString(), false);
            }

解决方案 »

  1.   

    除非你把一个Text框,在用户输入字符时显示*,数据保存到另外一个hidden框里直接对密码框不能赋值的
      

  2.   

    TextBox2.Attributes.Add("value",abc);
      

  3.   

    txtPassword.Attributes.Add("value","xzz");
      

  4.   

    首先扔一个hidefield控件id为hf1然后这样写
     if (!cs.IsStartupScriptRegistered(cstype, csname))
                {
                    System.Text.StringBuilder cstext = new StringBuilder();
                    cstext.Append("<script type=text/javascript> function DoClick() {");
                    cstext.Append("document.getElementById('txtPassword').value=document.getElementById('hf1').value;");
    cstext.Append("}</script>");
                    cs.RegisterStartupScript(cstype, csname, cstext.ToString(), false);
    }
    大概这样了,有些错误自己改一下吧,因为是根据你的代码来写的但是最好把这样数据放在服务器方,放在一个viewstate中或session中,写值的时候判断一下,这些东西中是不是空,如果是空拿控件中的值,不为空拿session中