简体   繁体   中英

Control 'ctl07' of type 'TextBox' must be placed inside a form tag with runat=server.

I have a problem you can see at the title.

 <form id="form1" runat="server">
    <div>
        <br />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
        <asp:TextBox ID="mac_id" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            Text="Temp Ekle" />
    </div>
    </form>

inside aspx.cs i create a table and i insert some values from database to this text box called "mac_id".

TableCell cel = new TableCell();
mac_id.Text = Convert.ToString(myDataTable.Rows[0][2]);
cel.Controls.Add(mac_id);
rw.Cells.Add(cel);

it is inside the form tag and it is runat="server".This is the code that using mac_id textbox.there is no code that manipulate that textbox.I only want to show the user the id.I am not using any render control or something that textbox has.I also check the other solutins but they are all using render or writer i am not thats because i open a new question. I hope i can explain my problem enough.Thanks for helping.

You can avoid this execption by overriding VerifyRenderingInServerForm

public override void VerifyRenderingInServerForm(Control control)
{
  /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
     server control at run time.
     Hence, no exception. */
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM