0

Hi I want to convert System.Web.UI.HtmlControls.HtmlInputText value into string.

Actually I am using authentication function in which i am using HTML controls :

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

*Now I am check above function on 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 )

}

Any suggestion regarding.

1
  • Ya, I know! but I was using: Authenticate_User(userid, pass) many times in the project & its really hard to change the code. Any method to type cast string into htmlinput. Commented Apr 2, 2013 at 11:25

2 Answers 2

1

there are two ways of doing it

Method 1:

change the parameter type of Authenticate_User(System.Web.UI.HtmlControls.HtmlInputText username, System.Web.UI.HtmlControls.HtmlInputText password) to private void Authenticate_User(String username, String password)

of if you want to typecase string to htmlinput then use this

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 });
};
Sign up to request clarification or add additional context in comments.

2 Comments

works here. can you show what changes you have made. coz it works man
also try giving its length near by value
0

try the following

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.
  }

to cast you need to make a new object

HtmlInputText obj=new HtmlInputText();
obj.Value="";

2 Comments

Thanks for the answer ! but I am returning this value via cookies(& it return in string). So is there any method to type cast string into htmlinput.
u can not cast but create new object and set value of that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.