Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.TextBoxMode'

  • Thread starter Thread starter jc
  • Start date Start date
J

jc

This has to be something really stupid. I'm getting the above error on
the second to last line of this code.
I just want set the textbox's TextMode to multiline.

namespace BaseWSP{
public class BaseWSP : System.Web.UI.WebControls.WebParts.WebPart
{
TextBox text_box_input = new TextBox();
Label labelmsg = new Label();
Button button_submit = new Button();
Button button_reset = new Button();
DropDownList ddl = new DropDownList();
protected override void CreateChildControls()
{
text_box_input.ID = "txt_input";
text_box_input.TextMode = "multiline";
text_box_input.Rows = 15;


Thanks for any help or information.
 
jc presented the following explanation :
This has to be something really stupid. I'm getting the above error on
the second to last line of this code.
I just want set the textbox's TextMode to multiline.

namespace BaseWSP{
public class BaseWSP : System.Web.UI.WebControls.WebParts.WebPart
{
TextBox text_box_input = new TextBox();
Label labelmsg = new Label();
Button button_submit = new Button();
Button button_reset = new Button();
DropDownList ddl = new DropDownList();
protected override void CreateChildControls()
{
text_box_input.ID = "txt_input";
text_box_input.TextMode = "multiline";
text_box_input.Rows = 15;


Thanks for any help or information.

text_box_input.TextMode = TextBoxMode.MultiLine;

When you specify "multiline" in an aspx page, there is an automatic
conversion to a value of the TextBoxMode enum.
In codebehind you have to use the enum.

Hans Kesting
 
This has to be something really stupid. I'm getting the above error on
the second to last line of this code.
I just want set the textbox's TextMode to multiline.

namespace BaseWSP{
public class BaseWSP : System.Web.UI.WebControls.WebParts.WebPart
{
TextBox text_box_input = new TextBox();
Label labelmsg = new Label();
Button button_submit = new Button();
Button button_reset = new Button();
DropDownList ddl = new DropDownList();
protected override void CreateChildControls()
{
text_box_input.ID = "txt_input";
text_box_input.TextMode = "multiline";
text_box_input.Rows = 15;

Thanks for any help or information.

The error is pretty clear. You are assigning a string to the TextMode
property. The TextMode property is not a string. You need code like
this:

text_box_input.TextMode = TextBoxMode.MultiLine

Chris
 
Back
Top