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?

3 Answers 3

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

1 Comment

what if the textarea is inside a tablerow
0

You can try this.

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

Refer to this.

2 Comments

What does frm refer to? Is that <form id="frm" runat="server">?
For more info. Check out this.
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.

Comments

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.