Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending to BODY element

Just before (or during) rendering page I would like to append a piece of code (java script). However when I try to add new LiteralControl via Page.Controls property I get an error:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

How to get round that issue?

like image 913
dragonfly Avatar asked Nov 24 '25 00:11

dragonfly


1 Answers

To avoid that problem do the following:

  1. Add a <asp:Placeholder id="Placeholder1" runat="server" /> control in your ASPX
  2. In code behind add the control to the Controls collection of that placeholder:

    Placeholder1.Controls.Add(myControl);

like image 158
Atanas Korchev Avatar answered Nov 26 '25 12:11

Atanas Korchev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!