使用C#加载文本从$ C $在asp.net背后Ç的textarea [英] load text into textarea from code behind in asp.net using C#

查看:135
本文介绍了使用C#加载文本从$ C $在asp.net背后Ç的textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1 asp.net页面和我想的文本加载到TextArea控件这是在aspx页面从成变量后面code(C#):

背后code:

  System.Web.UI.HtmlControls.HtmlTextArea输出1 =
    (System.Web.UI.HtmlControls.HtmlTextArea)(的FindControl(textarea1));
Output1.Value = Output.ToString();

ASP:

 < D​​IV的风格=宽度:78%;浮动:权利;高度:85px;显示:块;
    类=message_text_box_left>    < textarea的ID =textarea1NAME =textarea1COLS =30行=3
        类=message_text_box称号=分享你的Idias在这里......
        的tabindex =1的onkeyup =addrow_fun();>&下; / textarea的>
< / DIV>

但它给错误,如


  

对象引用未设置到对象的实例。



解决方案

您应该添加

  =服务器

属性的文本区域。

或者,preferable你应该使用的 文本框 ASP.NET控件和设置的 的TextMode 属性 TextBoxMode.MultiLine 。举例如下:

背后code:

  Output1.Text = Output.ToString();

ASP:

 < D​​IV的风格=宽度:78%;浮动:权利;高度:85px;显示:块;
    类=message_text_box_left>    < ASP:文本框ID =输出1行=3
        的CssClass =message_text_box工具提示=这里我们分享您的想法......
        的TextMode =多行/>
< / DIV>

I've one asp.net page and I want to load text into the textArea control which is in aspx page from into a variable in code behind (C#):

Code behind:

System.Web.UI.HtmlControls.HtmlTextArea Output1 = 
    (System.Web.UI.HtmlControls.HtmlTextArea)(FindControl("textarea1"));       
Output1.Value = Output.ToString();

ASP:

<div style ="width: 78%; float: right; height: 85px; display: block;" 
    class="message_text_box_left">

    <textarea id="textarea1" name="textarea1" cols="30" rows="3" 
        class="message_text_box" title="Share your Idias here..." 
        tabindex="1" onkeyup="addrow_fun();"></textarea>                        
</div>  

but it is giving error like

Object reference not set to an instance of an object.

解决方案

You should add the

runat="server"

attribute to the text area.

Or, preferable you should use the TextBox ASP.NET control and set the TextMode property to TextBoxMode.MultiLine. Example follows:

Code behind:

Output1.Text = Output.ToString();

ASP:

<div style ="width: 78%; float: right; height: 85px; display: block;" 
    class="message_text_box_left">

    <asp:TextBox ID="Output1" Rows="3" 
        CssClass="message_text_box" ToolTip="Share your ideas here..." 
        TextMode="MultiLine" />                        
</div>  

这篇关于使用C#加载文本从$ C $在asp.net背后Ç的textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆