打电话回发的UpdatePanel发行后的JavaScript函数 [英] Call a Javascript Function after UpdatePanel Postback Issue
问题描述
我基本都在我的UpdatePanel的文字,其基于我在codebehind的方法的JavaScript数组。
I basically have in my UpdatePanel a literal that generates a javascript array based on a method in my codebehind.
我没有问题,当涉及到我的加载页面加载内容。但是,如果我试图进行搜索,以更新我的UpdatePanel内我的javascript数组文本,我发现文字被更新后,回传的JavaScript已经解雇了。
I don't have an issue when it comes to loading my content on page load. But if I try and carry out a search to update my javascript array literal within my updatepanel, I found that the literal gets updated on postback after the javascript has already fired.
下面是什么,我有一个基本的例子:
Here is a basic example of what I have:
<script type="text\javascript">
function BindMyFunction(itemList)
{
//Do something
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- Literal containing generated JS array -->
<asp:Literal ID="ProfileJavscriptOutput" runat="server"></asp:Literal>
<ul id="person-search">
<li><asp:TextBox ID="TxtFirstname" runat="server" Text=""></asp:TextBox></li>
<!-- Update Literal onClick -->
<li><asp:ImageButton CssClass="searchbtn" ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" /></li>
</ul>
<!-- Some jCarousel rendered -->
</asp:UpdatePanel>
我一直在看下面的帖子:
I've been looking at the following posts:
ASP.NET - 的UpdatePanel和JavaScript
的UpdatePanel回发后调用JavaScript
call javascript after updatepanel postback
但我似乎不能正确地将其应用到我的code。
But I can't seem to apply it correctly to my code.
它正常工作时我不使用一个UpdatePanel。但它是一个要求,这样,当搜索被执行的页面位置不移动。
It works fine when I don't use an UpdatePanel. But it is a requirement so that the page position does not move when searches are carried out.
推荐答案
您可以添加以下code在Page_Load事件:
you can add the following code in Page_Load event:
ScriptManager.RegisterStartupScript(Me.rptGridAlbum, rptGridAlbum.GetType, "scriptname", "somejavascript", True)
这将在AJAX回调后解雇你的页面上的JavaScript。
This will fire the javascript on your page after the AJAX callback.
<一个href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerstartupscript.aspx">MSDN
这篇关于打电话回发的UpdatePanel发行后的JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!