从Javascript回发:我可以将回发链接到更新面板触发器吗? [英] Post back from Javascript: Can I link a postback to an Update Panel trigger?

查看:53
本文介绍了从Javascript回发:我可以将回发链接到更新面板触发器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的aspx代码中有一个javascript函数,调用__doPostBack()函数。在我后面的代码中,我将根据其他控件的值更新下拉列表控件中的选定项。功能正常,但回发正在渲染整个页面,而且速度很慢。我想使用Updatepanel,以便我只重新渲染下拉列表。是否有可能以某种方式向UpdatePanel添加触发器以链接到此回发,如链接到控件事件的触发器?或者还有其他方法可以达到这个目标吗?



提前致谢。



喜欢这样:

Hi All,

I have a javascript function in my aspx code calling __doPostBack() function. In my code behind for this post back I update a selected item in a drop down list control depending on other control's value. The functionality is working fine but the postback is rendering the entire page and it is slow. I want to use an Updatepanel so that I only re-render the drop down list. Is it possible to somehow add a trigger to an UpdatePanel to link to this postback like the trigger to link to an control event? Or is there another way to achieve this?

Thanks in advance.

Like this:

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
  <ContentTemplate>
      <asp:DropDownList ID="ddlItem1" runat="server" DataTextField="Item1" DataValueField="Item1">
      </asp:DropDownList>
  </ContentTemplate>
<Triggers>
      <asp:AsyncPostBackTrigger ControlID="ddlItem2" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>

推荐答案

第一种方法:: Javascript代码:

1st method :: Javascript Code:
function refreshddlItem2()
{
document.getElementById('<%= ddlItem2.ClientID %>').SelectedIndexChanged();
}



添加属性到下拉列表。


Add property to dropdownlist.

AutoPostBack="true"
onselectedIndexChanged="refreshddlItem2()"





第二种方法:



2nd Method:

protected void Page_PreRender(object sender, EventArgs e)
{




ClientScript.RegisterClientScriptBlock(typeof(Page), "UpdatePanelIDs", script, true);



}



第3种方法:

在dropdownlist控件中添加属性并在必要时调用javascript函数。


}

3rd Method:
Add attributes to dropdownlist control and call the javascript function when it is necessary.


这篇关于从Javascript回发:我可以将回发链接到更新面板触发器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆