Object reference not set as an instance of an object. Runat="Server" ASP

0

My problem is this:

They asked me not to put runat="server" to textArea1 . Then in the part of the code the label does not appear to me. I tried to trap the tag with the master.findcontrol() but it throws me a NullException (Object reference not set as an instance of an object) and therefore does not pass the data to textArea2

        

      

<%: Title% >.

      

Your application description page.

      

Use this area to provide additional information.

<textarea id="TextArea1" cols="20" rows="10"  ></textarea>

<asp:Button ID="Button1" runat="server" Text="Pasar A" OnClick="Button1_Click"/>

<textarea id="TextArea2" cols="20" rows="10" runat="server"></textarea>
 </asp:Content>

code Behind

public partial class About : Page
{


    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        if (!string.IsNullOrEmpty(Master.FindControl("TextArea1").ToString()))
        {
           TextArea2.InnerText = Master.FindControl("TextArea1").ToString();
        }

    }


}
    
asked by Dieguito Weed 12.09.2018 в 15:25
source

1 answer

2

If you remove the runat="server" from the control you will not be able to access it from the backend code

If you can access the value if you use the collection Request.Form[] but not the direct control because it would stop being an Html Control

var valor = Request.Form["TextArea1"];
    
answered by 12.09.2018 / 15:54
source