Control 'ctl07' of type 'TextBox'

2019-08-07 09:49发布

问题:

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.

回答1:

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. */
}