user1155194
user1155194

Reputation: 35

how I can read text from html textarea in asp.net page?

I set html textarea in asp.net page with out runat="server" and I need set the text in string variable by C# in code behind

Upvotes: 2

Views: 6378

Answers (6)

Janani M
Janani M

Reputation: 423

Kindly review this link

You can set data in code behind by using ViewData and can access them in html as explained in above link.

Upvotes: 0

Adam
Adam

Reputation: 379

couldn't you just save the value to a variable in your codebehind file and then on the webform itself just reference the variable by some manner such as <%= varName =>??

The above seem like a lot of work just to reference a variable that you can set quite easily in C# and then pull in the page load.

Upvotes: 0

Roy
Roy

Reputation: 81

I guess your trying to accomplish is to populate your textbox with the variable on the server side with out runat="server" set to the control.

You can do that with ajax and simple jquery.

Lets say your have this on your YourPage.aspx

<input id="txtMyTextBox" type="text" />

and next is a simple jquery

function getMytextValue() {
        $.ajax({
            url: "/MainPage.aspx/YourServerSideFunction",
            type: "post",
            data: "{ }",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            success: function (data) {
                //Get your value from JSON data.d;
                $('#txtMyTextBox').val(data.d);
            },
            error: function (request, status, err) {
                //Do something here for error;
            }
        });
    }

And now just call the jquery on what ever event you like.

PS: dont forget to create a [WebMethod] on your code behind.

Hope this help you! :D

Upvotes: 0

u936293
u936293

Reputation: 16264

An ASP.NET TextBox control with the TextMode property set to MultiLine will generate an Html TEXTAREA control.

So instead of crafting Html TEXTAREA manually, you can just drop a TextBox control and have:

 <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>

and then in your code behind:

 TextBox2.Text = "... blah blah blah...";

Upvotes: 2

Mido
Mido

Reputation: 131

you can take a look at this thread

i think its the same, hope it helps

Upvotes: 0

Rohith Nair
Rohith Nair

Reputation: 1070

Use Request.Form Collection http://msdn.microsoft.com/en-us/library/ms525985(v=vs.90).aspx to retrieve values..

Upvotes: 0

Related Questions