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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:42:39+00:00 2026-05-11T21:42:39+00:00

I have a UserControl that I want to include in a page multiple times

  • 0

I have a UserControl that I want to include in a page multiple times programatically based on some business rules. Currently the control has a JavaScript function that must be called on the ASP.NET AJAX pageLoad event.

I’m using a pattern where the Master page has a pageLoad function that calls a contentPageLoad function on any ContentTemplate, if the function exists. The ContentTemplate that holds the UserControl in question would then be responsible for calling the appropriate function on the UserControl during this event.

Right now, the JavaScript is inline in the .ascx for the UserControl, but I have a feeling that I’ll need to use the Page.ClientScript property to inject it via code behind. My question is: how do I make sure that my function names don’t get clobbered, and make sure that the appropriate method gets called for each UserControl?

FYI: the code that needs to get executed for each UserControl is a block of jQuery that creates a Multi-Select control from a standard HTML <select>.

EDIT: RegisterStartupScript was suggested, but this runs before the DOM is finished loading. Wrapping the function in a jQuery Document.ready() doesn’t seem to help. The user control is running inside of an UpdatePanel, so I don’t really have a choice about how to call this script.

  • 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-11T21:42:39+00:00Added an answer on May 11, 2026 at 9:42 pm

    So I ended up taking a hybrid approach to what @DDaviesBrackett suggested. I am registering a function with Page.ClientScript, not as a startup script, but as a ClientScriptBlock. The function uses classes instead of IDs (and thus, ClientIDs) to attach to each control. The basic structure is:

    if(!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(),"scriptkey"))
    {
        Page.ClientScript.RegisterClientScriptBlock(
            Page.GetType(),"scriptkey",script,true);
    }
    

    with the following script:

    function bindMultiSelects() {
        $('.multiselectclass').multiSelect({
            oneOrMoreSelected: '*', 
            noneSelected: 'Select Item(s)'
        });
    }
    

    (using the awesome jQuery MultiSelect plugin)

    Again, this works because my Master page creates a page_load method that then calls a method on the content, which then calls bindMultiSelects. Just for my own reference, the page_load and contentPageLoad functions both follow this “plugin” pattern I found here:

    if(typeof functionname=='function') {
        functionname()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user control that contains multiple controls (CheckBox, Button, Label...). I want
I have a usercontrol that has some checkboxes in it. On postback i want
I have a UserControl that adds other UserControls, but I want the latest control
I have a UserControl that I want to add at runtime to my current
I have an UserControl that contains a Button : <UserControl> <Button> </UserControl> I want
I have a UserControl with a Border element within it that I want to
I have a usercontrol that I want to use as a ListBoxItem. <ListBox.ItemTemplate> <DataTemplate>
I have a UserControl that I want to participate in data binding. I've set
I have a Custom usercontrol that I want to enlarge. I tested this whit
I have a UserControl that incorporates a textbox. I want to set the keyboardfocus

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.