At first glance, it should be easy to inject a javascript, but it took a little bit of digging around to figure out the resolution, the key is to use ScriptManager.
1: <asp:UpdatePanel ID="myUpdatePanel" UpdateMode="Conditional" runat="server">
2: <Triggers>
3: <asp:AsyncPostBackTrigger ControlID="btnClick" EventName="Click" />
4: </Triggers>
5: <ContentTemplate>
6: <asp:ImageButton
7: ID="btnClick"
8: ImageUrl="ClickMe.png"
9: runat="server"
10: CausesValidation="false"
11: OnClick="btnClickEvent"
12: ToolTip="Click Me"
13: AlternateText="Click me!" />
14: </ContentTemplate>
15: </asp:UpdatePanel>
We wanted to dynamically inject some JavaScript code. If my ScriptManager control has EnablePartialRendering set to true, it's a simple matter of registering the script. What i didn't realize earlier was that you don't need to the use the current page or current event, you need to call the static method on the ScriptManager class.
1: protected void btnClickEvent(object sender, ImageClickEventArgs e)
2: {
3: btnClick.Text = "I was clicked."
4: btnClick.Disabled = true;
5: ScriptManager.RegisterClientScriptBlock(myUpdatePanel, typeof(UpdatePanel),myUpdatePanel.ClientID, "alert('It worked!');",true);
6: }
That's it! Use the ScriptManager class, point it to the instance of your update panel, pass it a unique key and then the JavaScript you want, and it will be executed once the update panel is done rendering.