ASP.NET Webforms: Dynamically add asp button to page but is not visible

moondaddy 911 Reputation points
2021-03-27T04:49:14.497+00:00

From an asp button click event I’m adding innerhtml to a div tag. This inner html in an asp button, however, after adding it, its not visible even though when I inspect the page it is there.

81967-image.png

and this is the div tag I'm adding it to:

82053-image.png

and here you can see it was added but its not visible:

82054-image.png

How can I make this work as expected? Thanks.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,247 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. XuDong Peng-MSFT 10,096 Reputation points Microsoft Vendor
    2021-03-29T03:02:10.293+00:00

    Hi @moondaddy ,

    According to your description, if you need to add a control to the page, you can create a control and then add it to the corresponding parent control.

    But these dynamically created controls will become invalid after postback, so you need to recreate them in Page_Load() or Page_Init().

    This is simple demo:
    82232-pagecode.png
    82251-codebehind.png

    Result:
    82252-result.gif

    Best regards,
    Xudong Peng


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments