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

你。 提交于 2019-12-13 00:07:54

问题


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


来源:https://stackoverflow.com/questions/12957280/control-ctl07-of-type-textbox-must-be-placed-inside-a-form-tag-with-runat-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!