Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9179799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:53:26+00:00 2026-06-17T17:53:26+00:00

Here is my sample code: <script type=text/javascript> $(function () { $(‘body’) .append(‘<form id=form1></form>’); //append

  • 0

Here is my sample code:

    <script type="text/javascript">
    $(function () {
        $('body')
            .append('<form id="form1"></form>'); //append a new form element with id mySearch to <body>
        $('#form1')
            .attr("runat", "server")
            .append('<asp:Button runat="server" ID="btn1"/>');
    });
    </script>

This is how my body tag looks like:

    <body>

    </body>

I get this error:

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

Thanks in advance! 🙂

Update: I tried to omit the

    .append('<asp:Button runat="server" ID="btn1"/>');

When I run the firebug i get this:

   <body>
        <form id="form1" runat="server"></form>
   </body>

It does have a runat=”server”. Why I can’t place my asp:Button inside it? o_O

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:53:28+00:00Added an answer on June 17, 2026 at 5:53 pm

    Your updated question is is still a wrong approach. You can’t do this:

    $('#form1').attr("runat", "server")
    

    and expect it to work the same as if you typed this:

    <form runat="server">
    

    because the tag above is processed server side and actually renders on the client side like this:

    <form method="post" action="default.aspx" id="ctl00">
    

    and that looks nothing like what you are doing.

    You have two options:

    1. Stop trying to add any ASP.NET controls (i.e. starts with <asp:) or anything with runat="server" in it with Javascript. If you really have to do this with Javascript, then use regular HTML controls.

    2. Stop using Javascript and actually correctly use <asp: controls or HTML controls with runat="server" and then do what you need to do from the code behind.

    And now for the tangent.

    Concerning your error of Control 'btn1' of type 'Button' must be placed inside a form tag with runat=server. Let’s say you correctly use <form runat="server"> and try again. You may find it (sort of) works!

    <form id="form1" runat="server">
        <asp:Button ID="btn2" Text="Button 2" runat="server" />
        <script>
            $(document).ready(function () {
                $('#<%= form1.ClientID %>').append('<asp:Button Text="Button 1" ID="btn1" runat="server"/>');
            });
        </script>
    </form>
    

    This will render, but it is not correct. Besides being confusing, nasty code, it only works because ASP.NET actually renders the HTML for that <asp:Button and puts it in the script block, so what is sent to the client is this (and two buttons.. but still not what you typed).

    <input type="submit" name="btn2" value="Button 2" id="btn2" />
    <script>
        $(document).ready(function () {
            $('#form1').append('<input type="submit" name="btn1" value="Button 1" id="btn1" />');
        });
    </script>
    

    And now for part you didn’t expect. From the code-behind, you can do this on Page Load:

    protected void Page_Load(object sender, EventArgs e)
    {
        btn1.Text = "This is Awful";
    }
    

    And instead of having two buttons that say Button 2 and Button 1 on the screen, the second button now says This is Awful.

    …but again, this is totally wrong and will break for most other <asp: controls if you try to do it (and I’m not sure why ASP.NET converts the code in the Javascript block at all). So, see the two options above on how you can proceed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my sample code is here include 'simple_html_dom.php'; function get_all_links($url){ global $host; $html = new
<script type=text/javascript> $(document).ready(function($){ $.supersized({ //Background image slides : [ { image : 'images/pendulumWeb.jpg' }
Here is my code <html xmlns=http://www.w3.org/1999/xhtml> <head runat=server> <title></title> <script type=text/javascript src=<%= ResolveUrl(Scripts/jquery-1.3.2.min.js) %>></script>
Here is the sample code that I ran on Visual Studio 2010: #include <iostream>
Here's an sample code, where only the string object is released. NSString *nameOfFile =
Here's the sample code: public static void col (int n) { if (n %
Here's the sample code: class TestAO { int[] x; public TestAO () { this.x
Here is the sample code, which produces interesting output: > gg<-data.frame(x=c(a,b),y=as.integer(c(1000,100000))) > gg x
Here is a sample code I'm working on: <%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default
Here's a sample code: #include <stack> #include <cstddef> template <std::size_t N, template <class> class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.