0

I generated a HTMLTextArea using string and Response.Write():

string area = "<textarea id=\"myArea{0}\" cols=\"30\" name=\"S1\" rows=\"5\" runat=\"server\"></textarea>";

Response.Write(String.Format(area,1));

After this, I don't know how to get the object of this myArea1.

Are there any way I can achieve this goal?

Microos
  • 1,728
  • 3
  • 17
  • 34

3 Answers3

1

The proper way to add System.Web.UI.HtmlControls. will be,

var newTextArea = new HtmlTextArea()
{
    ID = string.Format("myArea{0}", 1),
    Name = string.Format("S{0}", 1),
    Cols = 30,
    Rows = 5
};
Page.Controls.Add(newTextArea);

Then you can access it like,

var myTextArea = Page.FindControl("myArea1") as HtmlTextArea;
naveen
  • 53,448
  • 46
  • 161
  • 251
0

You can try this.

  HtmlTextArea txt = (HtmlTextArea)(Page.FindControl("myArea1"));
  string value = txt.Value;

Refer to this.

Community
  • 1
  • 1
Null
  • 511
  • 5
  • 22
0

You don't really need to access the TextArea object itself if you are only interested in getting the user input, which you should be able to find in Request.Form collection on form submission.

Michal Klouda
  • 14,263
  • 7
  • 53
  • 77