问题描述
我有两个用户控件一个asp.net页面。每一个在不同的UpdatePanel中的一个用户控件有三个文本框。我想更新基于文本的变化第二的UpdatePanel /集中出第一个用户的控制。我怎样才能访问这两个用户控件的文本框和其他控件的页面和文字上的变化更新的UpdatePanel?
I have an asp.net page with two user controls. Each of which are in separate updatepanel's One user control has three textboxes. I want to update the second updatepanel based on change of text/ focus out in first user control. How can I access both user control's textboxes, and other controls in page and update the updatepanel on change of text ?
updatepanel1
user control1
textbox1
textbox2
textbox3
updatepane2
usercontrol2
label1
问候,
阿西夫·哈米德
Regards,Asif Hameed
推荐答案
哇,UpdatePanel的!这需要我回来。触发UpdatePanel的从客户端回传异步一直有点杂牌的。常见的方式是注册一个隐藏按钮的Click事件AsyncPostBackTrigger,然后显式调用客户端上的单击事件。然而,间接的少一些层的解决方法是调用的ASP.NET AJAX库的__doPostBack()的JS函数。
Whoa, UpdatePanels! That takes me back. Triggering UpdatePanels to "postback" asynchronously from the client has always been a bit of a kludge. The common way was to register an AsyncPostBackTrigger with a hidden button's click event and then explicitly call its click event on the client side. However, a solution with a few less layers of indirection is to call the ASP.NET AJAX library's __doPostback() JS function.
您正在使用jQuery(可能是牵强考虑你还在使用的UpdatePanel!)假设,你可以添加一个事件处理程序到你的UserControl1的事件的内容'事件来触发UpdatePanel2的异步回送。我建议把这个JS你的UpdatePanel的一个之外。
Assuming you're using jQuery (which may be far-fetched considering you're still using UpdatePanels!), you can add an event handler to the 'focusout' event of your UserControl1 to trigger the asynchronous postback of your UpdatePanel2. I would recommend putting this JS outside of one of your UpdatePanels.
$('#userControl1').on('focusout', function() {
__doPostback('UpdatePanel2UniqueId', '');
});
我挖了一个很好的文章,解释了更加详细使用__doPostBack的技术。
I dug up a good article that explains the technique of using __doPostback in a bit more detail.
这篇关于基于texbox重点更新的UpdatePanel的迷失在asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!