您好我想将 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 )
}
关于。
的任何建议答案 0 :(得分:1)
有两种方法可以做到这一点
方法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 });
};
答案 1 :(得分: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="";