ASP.NET Update panel problem

2019-07-27 15:19发布

问题:

I have an update panel in my page which runs a function and sends an e-mail fine but when I added in the code below it doesn't seem to add it correctly to the page

Page.ClientScript.RegisterClientScriptInclude("myscript", "/scripts/myscript.js")

All the other stuff in my Sub runs fine but it just seems to not run that bit?

Any ideas?

EDIT

Here's my code

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="button1" EventName="Click" />
</Triggers>
<ContentTemplate>

    <asp:TextBox ID="textbox1" runat="server"
        Text="Name" />

    <asp:LinkButton ID="button1" OnClick="submitbutton1" runat="server"
        Text="SUBMIT" />

</ContentTemplate>
</asp:UpdatePanel>

And the Sub

Sub submitbutton1(ByVal sender As Object, ByVal e As EventArgs)
    Response.write("Test")      

    Page.ClientScript.RegisterClientScriptInclude("myscript", "/scripts/myscript.js")

End Sub

回答1:

Use ScriptManager.RegisterClientScriptInclude. There is a catch, though. For each script that you want to include asynchronously, you must end it with

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();