question

moondaddy-8531 avatar image
0 Votes"
moondaddy-8531 asked XuDongPeng-MSFT answered

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

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.


dotnet-aspnet-general
image.png (8.5 KiB)
image.png (5.0 KiB)
image.png (17.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

XuDongPeng-MSFT avatar image
0 Votes"
XuDongPeng-MSFT answered

Hi @moondaddy-8531 ,

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.



codebehind.png (31.9 KiB)
result.gif (200.3 KiB)
pagecode.png (16.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.