0

您好我想将System.Web.UI.HtmlControls.HtmlInputText值转换为字符串。

实际上我正在使用身份验证功能,其中我正在使用 HTML 控件:

private void Authenticate_User(System.Web.UI.HtmlControls.HtmlInputText username, System.Web.UI.HtmlControls.HtmlInputText password)
  {
//-- doing some code here & Save credentials into cookies.
  }

*现在我在 page_load 上检查上述功能:*

 protected void Page_Load(object sender, EventArgs e)
{
string userid = Request.Cookies["UserDetails"]["UserName"].ToString();
string pass = Request.Cookies["UserDetails"]["Password"].ToString();

Authenticate_User(userid, pass);  //---- It gives some conversation error (HTML contorl to string )

}

有关的任何建议。

4

2 回答 2

1

有两种方法可以做到

方法一:

将参数类型更改Authenticate_User(System.Web.UI.HtmlControls.HtmlInputText username, System.Web.UI.HtmlControls.HtmlInputText password)private void Authenticate_User(String username, String password)

如果你想将字符串类型化为 htmlinput 然后使用这个

protected void Page_Load(object sender, EventArgs e)
{
    string userid = Request.Cookies["UserDetails"]["UserName"].ToString();
    string pass = Request.Cookies["UserDetails"]["Password"].ToString();

    Authenticate_User(new System.Web.UI.HtmlControls.HtmlInputText() {Value=userid, Size=userid.Length }, new System.Web.UI.HtmlControls.HtmlInputText() {Value=pass, Size=pass.Length });
};
于 2013-04-02T11:26:12.077 回答
0

尝试以下

private void Authenticate_User(System.Web.UI.HtmlControls.HtmlInputText username, System.Web.UI.HtmlControls.HtmlInputText password)
  {
 String _username= username.Value;
 String _pass=password.Value;
//-- doing some code here & Save credentials into cookies.
  }

要转换,您需要制作一个新对象

HtmlInputText obj=new HtmlInputText();
obj.Value="";
于 2013-04-02T11:20:24.313 回答