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

  • Home
  • SEARCH
  • 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 3497236
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:20:46+00:00 2026-05-18T12:20:46+00:00

I have a tricky scenario whereby I want to add ScriptManager scriptreference only on

  • 0

I have a tricky scenario whereby I want to add ScriptManager scriptreference only on some conditions as follows

<asp:ScriptManagerProxy ID="scriptManagerProxy1" runat="server">
<CompositeScript>
    <Scripts>
        <asp:ScriptReference path=/...." />
    </Scripts>
</CompositeScript>
<asp:ScriptManagerProxy>

I want to make this script reference only on specific condition, so I did as below

<% if(xyzclass.property)
{ %>

above code

<% } %>

Once I do that, I get the error as

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

I googled up and tried to add ‘#’ as <%# but by adding ‘#’ it can’t find the class (xyzclass) and so get the error as

Expected class, delegate, enum, interface, or struct

I tried doing the work as mentioned here too
http://leedumond.com/blog/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks/

No luck so far. If I take the approach as mentioned in above link, it says something like

The base class includes the field '', but its type (System.Web.UI.ScriptManagerProxy) is not compatible with the type of control (System.Web.UI.ScriptManager).

Guys, what I need is just to add scripts via ScriptManager ONLY dynamically. Is there any way which is in practice good one too.

Thanks in advance,

Nimesh

  • 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-05-18T12:20:46+00:00Added an answer on May 18, 2026 at 12:20 pm

    If you want to add scripts based on conditions, programmably add them:

    ScriptManager mgr = ScriptManager.GetCurrent(this.Page);
    if (condition)
       mgr.Scripts.Add(new ScriptReference { Path = "~/script.js" });
    

    in code behind. Or, use a ScriptManagerProxy and define them in the user control or page itself. This is a great way to add scripts, but if you use a composite script, it does append these to the same composite script as the ScriptManager.

    HTH.

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

Sidebar

Related Questions

I am using a script by CSS-Tricks, which is pretty straightforward except my scenario
My searching skills seems to have failed me. I have this php object that
I have a Microsoft Dynamics CRM 4.0 form with an IFRAME on it that
I have a UINavigationController , complete with table view and associated magic. The data
For simplicity lets assume that I have a vector of N matrices each of
Hey guys, I'm at a deadlock here after thinking about this for too long.
I would like to be able to keep two separate branches in a git
is there a way to assign a special value when a binding cannot be
This is a best practice question, and I expect the answer to be it

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.