How to convert string variable to textbox variable?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sagardeshmukh310
    New Member
    • Feb 2008
    • 5

    How to convert string variable to textbox variable?

    Sir,

    Following is my code

    Textbox tb = (TextBox)Conver t.ToString(s) ;

    In above code i want to pass value present in the string variable 's' to the 'tb' variable but i am getting following error message

    "Cannot convert type 'string' to 'System.Web.UI. WebControls.Tex tBox"

    Plz suggest me how to write this code.

    Thanking You

    Sagar.
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi Sagar,

    The problem is you are not specifying the text property of your textbox. I'm not a C# programmer but something like:

    tb.text = s.ToString;

    will probably do the trick.

    I hope this helps,

    Dr B

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      If you are trying to assign a string value to a textbox so that the textbox will show the string in the typing area:
      Code:
      myTextBox.Text=mystringvalue;
      For what you are appearntly trying to do:
      Code:
      tb.Text=s.ToString();

      Comment

      • sagardeshmukh310
        New Member
        • Feb 2008
        • 5

        #4
        Originally posted by Plater
        If you are trying to assign a string value to a textbox so that the textbox will show the string in the typing area:
        Code:
        myTextBox.Text=mystringvalue;
        For what you are appearntly trying to do:
        Code:
        tb.Text=s.ToString();

        I want to use that string value in the textbox variable .

        I want that value if string should be stored in textbox variable ..

        Comment

        • sagardeshmukh310
          New Member
          • Feb 2008
          • 5

          #5
          Thanks for reply but i want value present in the string variable 's' to the 'tb' variable like if string s=sagar then tb=sagar and i can use tb as variable everywhere in webcontrol.

          Comment

          • vee10
            New Member
            • Oct 2006
            • 141

            #6
            Hi ,

            u can't assign a string variable to textbox variable.
            if u want to use that string value u should assign it to

            string s="sagar";
            TextBox t = new TextBox();
            t.Text = s;
            then use the t.Text as a variable


            Originally posted by sagardeshmukh31 0
            Thanks for reply but i want value present in the string variable 's' to the 'tb' variable like if string s=sagar then tb=sagar and i can use tb as variable everywhere in webcontrol.

            Comment

            Working...