Arizona1911
Arizona1911

Reputation: 2201

How to get value in html control on postback in asp.net

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.

Upvotes: 3

Views: 19220

Answers (3)

Rebecca Chernoff
Rebecca Chernoff

Reputation: 22607

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

If you have a textbox like

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

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

Request.Form["txt"]

Upvotes: 16

user281693
user281693

Reputation: 635

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.

Upvotes: 0

Jagmag
Jagmag

Reputation: 10356

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

Upvotes: 1

Related Questions