views:

4481

answers:

2

I'm having an annoying problem registering a javascript event from inside a user control within a formview in an Async panel. I go to my formview, and press a button to switch into insert mode. This doesn't do a full page postback. Within insert mode, my user control's page_load event should then register a javascript event using ScriptManager.RegisterStartupScript:

ScriptManager.RegisterStartupScript(base.Page, this.GetType(), ("dialogJavascript" + this.ID), "alert(\"Registered\");", true);

However when I look at my HTML source, the event isn't there. Hence the alert box is never shown. This is the setup of my actual aspx file:

<igmisc:WebAsyncRefreshPanel ID="WebAsyncRefreshPanel1" runat="server">
    <asp:FormView ID="FormView1" runat="server" DataSourceID="odsCurrentIncident">
        <EditItemTemplate>
            <uc1:SearchSEDUsers ID="SearchSEDUsers1" runat="server" />
        </EditItemTemplate>
        <ItemTemplate>
            Hello
            <asp:Button ID="Button1" runat="server" CommandName="Edit" Text="Button" />
        </ItemTemplate>
    </asp:FormView>
</igmisc:WebAsyncRefreshPanel>

Does anyone have any idea what I might be missing here?

+1  A: 

Have you tried using RegisterClientSideScript? You can always check the key for the script with IsClientSideScriptRegistered to ensure you don't register it multiple times.

I'm assuming the async panel is doing a partial page past back which doesn't trigger the mechansim to regenerate the startup scripts. Perhaps someone with a better understanding of the ASP.Net Page Life Cycle and the CLR can fill in those blanks.

Dave Anderson
you are correct, it wont trigger.
mattlant
I believe that using Page.RegisterClientSideScript has been depreciated for a while now, and when it comes to ajax postbacks we need to use the ScriptManager class. The closest match I can find is ScriptManager.RegisterClientScriptBlock, which doesn't appear to do anything within a formView.
Daniel
A: 

Try this, i got the same issue

ScriptManager.RegisterClientScriptBlock(MyBase.Page, Me.GetType, ("dialogJavascript" + this.ID), "alert(\"Registered\");", True)

This worked for me!

Christian