
[英]updating updatepanel on checkbox check ( which has client events and is in other updatepanel)
[英]updating second updatepanel using checkbox in first updatepanel
我有两个UpdatePanels。 一个UpdatePanel
具有一个CheckBox
和一个UserControl
。 UserControl有一些TextBoxes
。 在其他updatepanel中, Labels
很少。
我已将javascript函数添加到复选框以隐藏/显示它。 我正在使用Javascript来避免部分回发到服务器。
我还想在选中/取消选中复选框或用户控件的文本框中的某些数据更改时更新第二个UpdatePanel。
我可以在同一复选框上调用javascript函数以及服务器端函数吗? 我尝试将触发器添加到第二个updatepanel中,但未触发。
updatepanel1
checkbox
usercontrol
textbox1
texbox2
updatepanel2
label1 (updated on change of textbox 1)
label2 (updated on change of textbox 1)
我的复选框markupd看起来像这样
<asp:CheckBox ID="chkShippingSameAsBilling" runat="server"
Text=" Ship to same address"
AutoPostBack="true" Checked="true"
onclick="return ShowShippingAddress();"
/>
您可以在页面上添加一个虚拟按钮。 在按钮的第二个面板上设置异步回发触发器。
<asp:AsyncPostBackTrigger ControlID="btnAsync" EventName="Click" />
在复选框的选中更改中,在javascript中调用函数
btnAsync.Click();
它将异步回传第二个更新面板。 您可以从第二个面板回发中调用服务器端功能,也可以通过向虚拟按钮添加服务器端单击事件来调用服务器端功能。
在第二个updatePanel中放置一个隐藏按钮:
<div style="display:none">
<asp:Button ID="YourButton" runat="server" />
</div>
然后使用onclick函数单击:
function ShowShippingAddress()
{
document.getElementById('<%# YourButton.ClientID %>').click()
}
那应该导致第二个回发和更新。
您需要在第二个面板中设置触发器以使用复选框中的事件,这里有一些示例。
http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers
通过位于不同ContentPlaceHolder中的控件触发UpdatePanel的更新
另外,请看一下tickout.js或jquery,以获得一些更优雅的解决方案...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.