0

I have the following structure on a usercontrol that is loaded by a page (Parent UC):

<UpdatePanel>
  <UpdatePanel>
     .. In the codebehind, it loads a Child user control at runtime
  </UpdatePanel>
</UpdatePanel>

The UC has OnPageLoad registers a script.

ScriptManager.RegisterStartupScript(this, typeof(Page), "Load_" + this.ClientID, base.GetRegisterScript(this.ClientID), true);

The JS function never gets executed on async postbacks. If i remove the UpdatePanels, it works as expected

EDIT: Used this.GetType() instead of typeof(Page) but no luck

EDIT Again:

Matt - I tried to replace the typeof(Page) with the UC name. Here's the updated line:

ScriptManager.RegisterStartupScript(this, typeof(TemplateAreaTypeOne), "Load_" + this.ClientID, "...JS function here,,", true);

To clarify, the Page loads the Parent UC that has these UpdatePanels. The ParentUC then loads the ChildUC and the ScriptManager.RegisterStartuScript is used in teh ChildUC

EDIT

The markup has:

<script type="text/javascript">
//<![CDATA[
; findControl('PageLoadedHiddenTxtBox').value ='Set';OnLoadBegin('ctl00_WorkSpaceContent_ctlUnion1_ctlUnion1Child','Edit');OnLoadEnd('ctl00_WorkSpaceContent_ctlUnion1_ctlUnion1Child','Edit');
document.getElementById('ctl00_WorkSpaceContent_informationSummary').dispose = function() {
    Array.remove(Page_ValidationSummaries, document.getElementById('ctl00_WorkSpaceContent_informationSummary'));
}
//]]>
</script>

Note that the functions that are called are the OnLoadBegin and OnLoadEnd that have been added to the HTML

EDIT AGAIN

Got it to work using:

ScriptManager.RegisterStartupScript(this.Page, typeof(Page),....)

Not sure why it works when I use the reference to the Page.

  1. Will this work if I have multiple controls on the Page?
  2. Why does it work when I use a reference to the page?
13
  • Can you add the entire code of your update panel? Commented Mar 7, 2009 at 21:48
  • you need to control type not the type of this, whatever the control is that you are targetting you need that type registered for the startup script, so if you are loading a control MyControl then typeof(MyControl) the startupscript has to know what to target in the partial postback Commented Mar 7, 2009 at 22:01
  • i think you may have other problems here due to adding the control from codebehind, scriptmanager registers the scripts after the main markup has been parsed, so you can't use <% %> type replacements within the js that is added this way, id like to rule out the control type first though Commented Mar 7, 2009 at 22:04
  • ok, so can you check that your script is in the markup, stick an alert('hello') in there to make sure it is running, also you are calling a "js function here" is that in the markup or is it added using registerClientScriptBlock, and if so where ? Commented Mar 7, 2009 at 22:25
  • Yes, the JS is in the markup. I have edited my original post with the markup Commented Mar 7, 2009 at 22:26

1 Answer 1

2

your registerstartupscript needs to target the control NOT the page dont use typeof(Page)

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.