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 6802733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:15:32+00:00 2026-05-26T19:15:32+00:00

I have a slight problem with creating a button on the server side code.

  • 0

I have a slight problem with creating a button on the server side code. I am using stringbuilder to build a table in html and I want to create a new button object and pass it into my stringbuilder object. The problem I have is my page doesn’t compile when I am debugging. I want to give my button object a runat=”server” property but I don’t know how to.

Button add_img_popup = new Button();
            add_img_popup.Text = "Add new Image"; // text
            add_img_popup.Click += new EventHandler(addImgPopup_Click); // click event handler
            add_img_popup.Enabled = true;
            add_img_popup.ID = "btn_add_img_popup"; // programmatic id

            Page.Controls.Add(add_img_popup); // add to page controls so it renders

            st.Append("<tr>");
            st.Append("<td>");
            st.Append(add_img_popup); // pass to string builder
            st.Append("</tbody>");
            st.Append("</table>");

And the message the server gives me.


Server Error in ‘/’ Application.

Control ‘btn_add_img_popup’ of type ‘Button’ must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control ‘btn_add_img_popup’ of type ‘Button’ must be placed inside a form tag with runat=server.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): Control ‘btn_add_img_popup’ of type ‘Button’ must be placed inside a form tag with runat=server.]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +8702387
System.Web.UI.WebControls.Button.AddAttributesToRender(HtmlTextWriter writer) +54
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +20
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +20
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

  • 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-05-26T19:15:32+00:00Added an answer on May 26, 2026 at 7:15 pm

    do not do this:

    Page.Controls.Add(add_img_popup);
    

    have a div with runat=server in your page inside the Form tag and if the div is called myDiv then do this:

    myDiv.Controls.Add(add_img_popup);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am new here. i have a slight problem; PLease look at the following code
I've wrote this simple piece of code. And I have a slight problem with
I have a slight problem, I'm making a dropdown using the help from someone
I have a slight problem with this code: string[] sWords = {Word 1, Word2}
slight problem. I have a 20 x 20px delete icon which I want to
Have a slight problem. Trying to post XML to a server. To do this,
I have a slight problem. I am using a working script (works on my
I am creating a coverflow plugin but I have a slight problem when it
I am running into a slight problem in Oracle SQL. I have a table
I'm learning Silverlight for WP7 and have come across a slight problem: I want

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.