How do I set text to textarea in formview in insert mode

544 views Asked by At

DemHere is my textarea control:

<textarea id="Physical_DemandsTextBox" runat="server" cols="35" rows="6" value='<%# Bind("Physical_Demands") %>' />

Here is my logic that works with the other asp:TextBox controls

if (FormView1.CurrentMode == FormViewMode.Insert)
   {
       TextBox txtPhyDem = FormView1.FindControl("Physical_DemandsTextBox") as TextBox;
   }

   if (txtPhyDem != null)
   {
         txtPhyDem.Text = "Failed Test of the Testing Testers.";
   }         

When I run the application on insert mode the text area is blank. How do I fix this?

2

There are 2 answers

0
Felipe Oriani On

You could use the Body property, for sample:

if (FormView1.CurrentMode == FormViewMode.Insert)
{
   Physical_DemandsTextBox.Body = "Failed Test of the Testing Testers.";
}

but you also could use directly the asp.net control what is better, for sample, in webform:

<asp:TextBox id="Physical_DemandsTextBox" runat="server" 
                                          TextMode="Multiline" 
                                          Columns="35" 
                                          Rows="6" />

and code behine:

if (FormView1.CurrentMode == FormViewMode.Insert)
{
    Physical_DemandsTextBox.Text = "Failed Test of the Testing Testers.";
}
0
Bhavesh Kachhadiya On

You Just need to replace textarea with textbox control as follow:

    <asp:TextBox ID="Physical_DemandsTextBox" 
        TextMode="MultiLine" Rows="6" Columns="35" 
        runat="server" 
        Text='<%# Bind("Physical_Demands") %>'></asp:TextBox>