1

I'm working on a project that contains a single page (home.aspx).

Home.aspx contains a ScriptManager and an UpdatePanel — a div with some LinkButtons that load related UserControls.

Some of those user controls contains javascript. My problem is that the javascript doesn't run on time (after LinkButton click or UC loads).

How do I solve this problem?

1
  • 1
    Please post the relevant code Commented Sep 11, 2009 at 21:00

3 Answers 3

1

Make sure your script is registered with the ScriptManager.

Sign up to request clarification or add additional context in comments.

Comments

0

If the user controls have JS inline, it will not run; JavaScript added by setting the innerHTML of an element (which is what UpdatePanel does) does not run.

As Rick Schott mentions, if the user controls register their script with the ScriptManager - either by including asp:ScriptReferences in their ScriptManagerProxy or by adding it from their codebehind using one of the ScriptManager.Register* variants - it will run.

Comments

0

Thanks For your Answers , But I had examined This solutions . User Controls Haven't Script Manager , Script Manager Placed in Home.aspx . I use both Page.RegisterClientScriptBlock , Page.RegisterStartupScript , ... But These don't work properly . Java script Codes in UC are in Script tag in top of UC Like Below :

                   function pageLoad() {
   $addHandler($get("<%=Button2.ClientID%>"), 'click', cp);

}
function cp() {

  /* Do shomthing ... */

}

//*################ END OF JAVASCRIPT CODES

In above JS Code Button2 is a asp Button placed in UC . I Find A New Thing today : If add defer='defer' in above Script tag it runs like a charm! But this solution is for IE(ONLY) , So this isn't the best solution . What Can i do more ...?

1 Comment

ScriptManager.Register* is static. If you user control is in a page that has a ScriptManager(required with an UpdatePanel) then it will find it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.