2

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

1
  • 4
    Then add runat="server". It's not so bad ;) Commented Apr 29, 2012 at 21:35

6 Answers 6

2

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

Comments

0

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

7 Comments

How does it help OP to set the textarea's value? The HttpRequest.Form collection is readonly(for logical reasons).
@Tim you are correct , it will retrieve values and question was to set it..My bad..
@tim then he can always set it via aspx via server variables right?
If he wants to access a control on serverside, he should make it a serverside control. Everything else would be pointless.
@tim yes , thats his requirement actually without a runat=server :) .Thanks for correcting me there.
|
0

you can take a look at this thread

i think its the same, hope it helps

Comments

0

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

Comments

0

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.

Comments

0

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.

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.