tags:

views:

33

answers:

3

I have an html control (not a server control) like textarea. How can I get the value in this control from the server side when I cause a postback by clicking on a button, without writing the value in the url.

A: 

You can add a runat="server" attribute to the HTML controls.

This attribute indicates that the element should be treated as a server control.

Once that is added, you can programatically access your HTML controls on the server side in your code behind just like you would use a server control.

All HTML server controls must be within a tag with the runat="server" attribute

Refer Link

InSane
This is somewhat true as adding `runat="server"` is one way. A control doesn't **have** to be a server control for the value to be sent across the wire. You seem to be talking specifically about 2 different things, one of them being Server Controls which the OP says he/she is not talking about.
rchern
I cannot add runat="server" because I am building the controls dynamically.
Arizona1911
@rchern - agreed - i thought that the problem the OP had was just that he had HTML controls - which he wanted to access on the server side. Thats what the question seemed to be asking, atleast to me :-) ? Based on the additional info, maybe not quite
InSane
@InSane, the distinction here is between a regular html control (`input`), an Html Server control (`HtmlInputText`), and an ASP.NET control (`asp:Textbox`).
rchern
+1  A: 

You'll need to reference out of the Form object.

If you have a textbook like

<input type="text" id="txt" name="txt" value="Testing 1 2 3..."/>

Then you could access it in your code-behind like so...

Request.Form["txt"]
rchern
I did this and it did not work. My form looks like this<form method="post" enctype="multipart/form-data" runat="server"> <textarea id="description"></textarea></form>If I do Request.Form["description"] I get a null exception
Arizona1911
@Arizona, Add the name attribute.
rchern
Give your `textarea` a name as well, such as `<textarea id="description" name="description"></textarea>`. I believe the name of the html element is what becomes the key in the `Request.Form` array.
wsanville
Ah! That's what I was missing. Thanks!
Arizona1911
A: 

You can do it using asmx web service. But I guess this would be a bad way of doing it. You need to call your web method from javascript code. Personally I would go by adding runat = server as one of the poster suggested but I am just suggesting web service as one way to go about even though not so elegant.

Uh, a web service??
rchern
hmm from javascript he can send the textbox content as a parameter to a web method written in .asmx file.
Yes, but here, *why*?
rchern
hmm because he said he cannot have runat=server. With my rep score, I cant add comments to his question nor to others answer. And his question was not very clear either. I just said it can be done as reply to Noon Silks comment that it cant be done. Request.Form is correct way of doing it and it struck to me after seeing your answer