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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:37:01+00:00 2026-06-08T07:37:01+00:00

I have an HtmlGenericControl which is a simple DIV with runat=server This Control is

  • 0

I have an HtmlGenericControl which is a simple DIV with runat=server

This Control is embedded inside of an ASCX WebControl which resides on multiple pages. At Page_Load this element is populated by a repeater that is data-bound to database data that is Page Specific.

The trouble I’m having is ASCX WebControls don’t seem to read the contents of their own elements very easily.

So far this has failed:
How do I get the HTML output of a UserControl in .NET (C#)?

I’m looking for a way to get the contents of the HtmlGenericControl inside of a button click. How would I do that?

Simplifying previous question. Retrieve HTML of specific element in ASCX

  • 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-08T07:37:02+00:00Added an answer on June 8, 2026 at 7:37 am

    OK, I got it working (I think…)

    Output

    enter image description here

    ASPX Code behind

        public override void VerifyRenderingInServerForm(Control control)
        {
            //base.VerifyRenderingInServerForm(control);
        }
    

    ASPX markup

    %@ Page EnableEventValidation="false" .....
    

    User control code behind

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                var d = new QuestionsContext().GetQuestions();
    
                this.repeater.DataSource = d;
                this.repeater.DataBind();
            }
        }
    
        protected void getContent_Click(object sender, EventArgs e)
        {
            var sb = new StringBuilder();
    
            this.generic.RenderControl(new HtmlTextWriter(new StringWriter(sb)));
    
            string s = sb.ToString();
    
            this.Trace.Warn(Server.HtmlEncode(s));
            this.message.Text = Server.HtmlEncode(s);
        }
    

    User control markup

    <div runat="server" id="generic">
        <asp:Repeater runat="server" ID="repeater" >
            <ItemTemplate>
                <%# Eval("QuestionText") %>
            </ItemTemplate>
        </asp:Repeater>
    </div>
    
    <br />
    <asp:Button Text="Get content" ID="getContent" runat="server" OnClick="getContent_Click" />
    <br />
    <asp:Label ID="message" runat="server" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three ul like this : <ul id=column3 class=column runat=server> </ul> <ul id=column4
I have masterpage which has runat=server & Id set on body tag. see below
I have a server control that I have written, which generally works fine. However
I have a link that is located inside a content control. This link calls
Placing an image inside a Span (here : HtmlGenericControl ) programmatically Want to have
have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have a short snippet of C# code like this: HtmlGenericControl titleH3 = new
I have a unordered list in my master page.... <ul id=mainMenu runat=server> <li id=mainHome
I'm creating DIV controls from code behind using this code - System.Web.UI.HtmlControls.HtmlGenericControl dynDiv =

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.