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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:54:39+00:00 2026-05-25T05:54:39+00:00

This might fall into the I think you’re doing it wrong category, but I

  • 0

This might fall into the “I think you’re doing it wrong” category, but I have a usercontrol that has javascript in it and I want to dynamically load it in an update panel. This is so the initial page load footprint is small, but if the user makes the request the control is loaded (nothing unusual).

I’m finding my javascript is not being executed when the control is loaded. Is there some magic to make the javascript execute, or will it never happen because the browser won’t re-parse the loaded html for tags?

My User Control

<div>hello</div>
<script type="text/javascript" >
alert('hello');
</script>

Page ascx

<asp:Button OnClick="LoadTheControl" runat="server">Click to Load</asp:Button>
<asp:UpdatePanel ID="myUPanel" runat="server">
    <asp:PlaceHolder ID="WantControlHere" runat="server" />
    <Triggers>
          <asp:AsyncPostBackTrigger ControlID="LoadTheControl" />
    </Triggers>
</asp:UpdatePanel>

Page cs

protected void LoadTheControl(object sender, EventArgs e)
{
    MyControl control = (MyControl)LoadControl("~/MyControl.ascx");
    control.ID = Guid.NewGuid().ToString();
    WantControlHere.Controls.Add(control);
}

Firebug shows me all the code of my control is there, but the javascript it is not executed.

Please point out my stupidity.

  • 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-25T05:54:39+00:00Added an answer on May 25, 2026 at 5:54 am

    I think in order to execute a javascript once your control is loaded, you have to register it using ScriptManager.RegisterStartupScript method.

    Inside the Page_Load method of your control register the script your want to execute like this:

    ScriptManager.RegisterStartupScript(this, this.GetType(), "sub", "alert('me');", true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Warm Standby SQL Server/Web Server This question might fall into the IT category but
This question has been asked a lot but everywhere the answers fall short. I
this might be fairly simple but I cant find my way around... I have
This might seems silly question but for me it is annoying. I have installed
This might seem like a stupid question I admit. But I'm in a small
This might be on the discussy side, but I would really like to hear
This might be a bit on the silly side of things but I need
This might seem obvious but I've had this error when trying to use LINQ
This might be an interesting question. I need to test that if I can
This might sound like a little bit of a crazy question, but how can

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.