2

I have the following:

<asp:UpdatePanel ID="upd" runat="server">
    <ContentTemplate>

        <script> alert("execute again"); </script>

        <asp:LinkButton ID="go" runat="server" Text="Exec JS" />

    </ContentTemplate>
</asp:UpdatePanel>

The first time the page renders the script is executed. If I click the button to cause a postback it doesn't execute again.

Is there a way to make it execute the scripts again?

3 Answers 3

5

Yo! There's an easy way to get the JavaScript to run again. Put the javascript on the HeadContent portion of your page:

<script> 

function BindIt()
{
    alert("execute again"); 
}

</script>

then on your page inside the update panel add portion with a call up to the function that you created for your javascript:

            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                <script type="text/javascript">
                    Sys.Application.add_load(BindIt);
                </script>
...

In a project that I was working on, I wanted all of the javascript on the page to run again, so I just put it all into a massive BindIt style function. It took me a while to figure it out and I tried many methods to get this to work but this was the only way I was ever able to get jquery to work with updatepanels

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

1 Comment

thank u,it is worked for me in my SharePoint 2010 FBA application
3

Since ASP is just pushing the raw data, not actually executing it you'll need to probably use the RegisterStartupScript method of the ScriptManager to programmatically inject the script to load after a partial postback.

EDIT More directly, try looking in to ScriptManager.RegisterStartupScript() for UpdatePanels. e.g.

Comments

3

If the JavaScript is jQuery related, following link would definitely help:

http://weblogs.asp.net/hajan/archive/2010/10/07/make-them-to-love-each-other-asp-net-ajax-updatepanels-amp-javascript-jquery-functions.aspx

I have personally used the 2nd method mentioned in this article, and it worked for me properly.

1 Comment

Yep! That's the same article I used. :)

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.