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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:20:43+00:00 2026-06-17T11:20:43+00:00

Simple question but I can’t find anything on it, is it possible to get

  • 0

Simple question but I can’t find anything on it, is it possible to get the contents of an asp:placeholder to a string? This would be great to do server side if it is possible.

Luke

  • 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-17T11:20:44+00:00Added an answer on June 17, 2026 at 11:20 am

    If you just want the textual content of a placeholder:

    string textualContent = ((LiteralControl) PlaceHolder1.Controls[0]).Text;
    

    Returns
    "Hello World"
    for:

    <asp:PlaceHolder ID="PlaceHolder1" runat="server">Hello World</asp:PlaceHolder>
    

    If you also want to get the html of the rendered control (and all of it’s child-controls):

    System.IO.TextWriter tw = new System.IO.StringWriter();
    HtmlTextWriter h = new HtmlTextWriter(tw);
    PlaceHolder1.RenderControl(h);
    string html = tw.ToString();
    

    For this aspx (the GridView is databound with some sameple data):

    <asp:PlaceHolder ID="PlaceHolder1" runat="server">
        <asp:Label ID="LblTest" runat="server">Test-Label</asp:Label>
        <asp:TextBox ID="TxtTest" runat="server" Text="Foo"></asp:TextBox>
        <asp:GridView runat="server" ID="GridView1"></asp:GridView>
        <textarea name="TextArea1" rows="2" cols="1">
        First line
        Second line
        </textarea>
    </asp:PlaceHolder>
    

    this html will be generated (depends on the browser):

    <span id="MainContent_LblTest">Test-Label</span><input name="ctl00$MainContent$TxtTest" type="text" value="Foo" id="MainContent_TxtTest" /><div>
        <table cellspacing="0" rules="all" border="1" id="MainContent_GridView1" style="border-collapse:collapse;">
            <tr>
                <th scope="col">ID</th><th scope="col">Text</th>
            </tr><tr>
                <td>1</td><td>Row #1</td>
            </tr><tr>
                <td>2</td><td>Row #2</td>
            </tr><tr>
                <td>3</td><td>Row #3</td>
            </tr><tr>
                <td>4</td><td>Row #4</td>
            </tr><tr>
                <td>5</td><td>Row #5</td>
            </tr>
        </table>
    </div>
        <textarea name="TextArea1" rows="2" cols="1">
        First line
        Second line
        </textarea>
    

    Note that you need to change your page directive to

    EnableEventValidation="false"
    

    and to override VerifyRenderingInServerForm in the Page

    public override void VerifyRenderingInServerForm(Control control)
    {
        /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
           server control at run time. */
    }
    

    when calling RenderControl manually.

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

Sidebar

Related Questions

This is probably a really simple question but I can't seem to find anything
This may be a simple question but I can;t find the answer anywhere. Here
this seems like a simple enough question but I can't seem to find a
This might be a simple question but I've searched and searched and can't find
I feel as though this this is a simple question, but can't find an
simple question maybe but can't find solution. I have button for refresh/update some contents
This is actually a pretty simple question but I can't seem to find the
This is probably a really simple question but I can't seem to get my
I feel this is a very simple question but I can't find to seem
This sounds like a simple question but I can't find good information. I'm writing

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.