2

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

DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316

1 Answers1

1

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.

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', '');
});

I dug up a good article that explains the technique of using __doPostback in a bit more detail.

Easily refresh an UpdatePanel, using JavaScript

Sean Glover
  • 1,766
  • 18
  • 31