Search code examples
c#asp.netvb.nethtmlcontrols

How can I generate a System.Web.UI.HtmlControls.HtmlTextArea with whatever attributes I want?


I have a very unique situation where I need to generate a <textarea> on the page, from code behind:

Public Class Textarea
  Inherits System.Web.UI.HtmlControls.HtmlTextArea
End Class

And the control:

<me:Textarea ... />

The problem is, my unique case requires me to use strange attributes. I basically need it to output something like this:

<textarea :class="{}" :id="something">

So I want to be able to do:

<me:Textarea :class="{}" etc. />

Is there an uncomplicated way to allow the rendering of exactly as I type? Or should I use another control? Build it from scratch in the render phase? I get errors about the tag not being well formed, so ultimately I just want it to spit out the <textarea> tag with the guts of it exactly as typed. Including C# in tags because doesn't matter. Will take any example.


Solution

  • All of these answers are excellent, but I wanted to share with everyone what I figured out how to do to make it as simple as possible.

    I just created a control:

    Public Class Wrapper
      Inherits Control
    End Class
    

    Then:

    <me:Wrapper>
      <textarea anything i want here... ></textarea>
    </me:Wrapper>
    

    Which just spits it out exactly as I typed. For some who question why even bother, I'm within another parser that uses a control builder and <textarea> is one of the child controls of it, so needed a workaround to just use regular HTML.