'Button' must be placed inside a form tag with runat=server

Thread is closed for posting
6 posts, 0 answers
  1. Adam Miller
    Adam Miller avatar
    3 posts
    Member since:
    Jul 2009

    Posted 08 Jul 2009 Link to this post

    Full Error: Control 'RadGrid1_ctl00_ctl02_ctl00_ctl04' of type 'Button' must be placed inside a form tag with runat=server

    Details:
    I'm placing a radgrid in a usercontrol, the usercontrol will be placed on an mvc page 6 times.  The radcontrol works if it is alone on a page (not int a user control) using the following code:
    <body>
        <form runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="false" runat="server">
            <MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn DataField="region" DataType="System.String" HeaderText="regionheader" />
                    <telerik:GridBoundColumn DataField="playCount" DataType="System.Int32" HeaderText="playcountheader" />
                </Columns>
            </MasterTableView>
            <ClientSettings>
                <DataBinding Location="/ASP/GridWS.asmx" SelectMethod="GetData" SelectCountMethod="GetCount" />
            </ClientSettings>
        </telerik:RadGrid>
        </form>
    </body>

    However I get the error when I attempt to place the grid in the control on the page.  If I move the <form> tag from the page to the control it will render without the error, but I need to have the form on the page as there are other controls that need to post, and basically because it seems like bad practice.
  2. Dallas Sehlhorst
    Dallas Sehlhorst avatar
    19 posts
    Member since:
    Feb 2006

    Posted 08 Jul 2009 Link to this post

    Adam,

    Try adding this to your View page:

    <script runat="server"
     public override void VerifyRenderingInServerForm(Control control) 
     { 
     } 
    </script> 

    I had a similar problem, and this fixed it.  This should suppress the rendering in a form issue you are experiencing.

    Hope this helps,

    -Dallas
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Adam Miller
    Adam Miller avatar
    3 posts
    Member since:
    Jul 2009

    Posted 08 Jul 2009 Link to this post

    overriding VerifyRenderingInServerForm allows me to remove the form tag from a simple page that does not use custom usercontrols that host the radgrid, but I still get the error on my page (which has a master page) when putting my user control on the page.
  5. Adam Miller
    Adam Miller avatar
    3 posts
    Member since:
    Jul 2009

    Posted 08 Jul 2009 Link to this post

    I have confirmed that this issue is directly associated with loading the radgrid in a user control on the mvc page.
    <ContentTemplate> 
        <% Html.RenderPartial("Widget", Model[0]); %> 
    </ContentTemplate> 

  6. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 09 Jul 2009 Link to this post

    Hello Adam,

    Can you please inspect the rendered html of the grid when it resides on the pag itself (using IE developer toolbar or Firebug) to see whether it contains input type=button inside its body? This can be the reason why you get the error that the button requires form with runat=server tag.

    To bypass it, disable the functionality which generates button(s) as part of the grid body.

    Kind regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Francis Go
    Francis Go avatar
    12 posts
    Member since:
    Jul 2009

    Posted 01 Sep 2009 Link to this post

    Hello Adam,

    I'm not sure if this will help you. I was getting the same error when I was adding my user controls to the page by code.
    I fixed it by changing Page.Controls.Add() to Form.Controls.Add. After doing that, the page rendered perfectly and the errors were gone.
    It's a bit confusing because on some pages, Page.Controls.Add() to add custom controls works fine. On others, it crashes.

    Hope this helps.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017