How do I reference the input of an HTML <textarea> control in codebehind?

后端 未结 5 1182
悲哀的现实
悲哀的现实 2020-12-15 14:53

I\'m using a textarea control to allow the user to input text and then place that text into the body of an e-mail. In the code behind, what is the syntax for referencing the

相关标签:
5条回答
  • 2020-12-15 15:30

    You should reference the textarea ID and include the runat="server" attribute to the textarea

    message.Body = TextArea1.Text;  
    

    What is test123?


    0 讨论(0)
  • 2020-12-15 15:32

    You are not using a .NET control for your text area. Either add runat="server" to the HTML TextArea control or use a .NET control:

    Try this:

    <asp:TextBox id="TextArea1" TextMode="multiline" Columns="50" Rows="5" runat="server" />
    

    Then reference it in your codebehind:

    message.Body = TextArea1.Text;
    
    0 讨论(0)
  • 2020-12-15 15:37

    You need to use runat="server" like this:

    <textarea id="TextArea1" cols="20" rows="2" runat="server"></textarea>
    

    You can use the runat=server attribute with any standard HTML element, and later use it from codebehind.

    0 讨论(0)
  • 2020-12-15 15:38

    Missed property runat="server" or in code use Request.Params["TextArea1"]

    0 讨论(0)
  • 2020-12-15 15:44

    First make sure you have the runat="server" attribute in your textarea tag like this

    <textarea id="TextArea1" cols="20" rows="2" runat="server"></textarea>
    

    Then you can access the content via:

    string body = TextArea1.value;
    
    0 讨论(0)
提交回复
热议问题