Asp.net 如何将System.Web.UI.HtmlControl.HtmlInputText值转换为字符串

Asp.net 如何将System.Web.UI.HtmlControl.HtmlInputText值转换为字符串,asp.net,Asp.net,您好,我想将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 &a

您好,我想将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.
  }
*现在我正在查看加载页面上的上述功能:

 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 )

}
任何有关的建议。

请尝试以下方法

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="";

有两种方法

方法1:

Authenticate\u用户(System.Web.UI.HtmlControls.HtmlInputText用户名、System.Web.UI.HtmlControls.HtmlInputText密码)的参数类型更改为
private void Authenticate\u用户(字符串用户名、字符串密码)

当然,如果您想将大小写字符串键入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 });
};

谢谢你的回答!但是我通过cookies返回这个值(&它以字符串形式返回)。所以有什么方法可以在htmlinput中输入cast字符串。你不能强制转换,只能创建新对象并设置thatYa的值,我知道!但是我在项目中多次使用:Authenticate_User(userid,pass)&更改代码非常困难。任何将强制转换字符串键入htmlinput.works的方法都可以在此处使用。你能告诉我你做了什么改变吗。因为它是有效的,所以试着让它的长度接近它的值