How can I call Ajax OnClick from a provider web part to a consumer web part
I'm trying to manage an ajax connection by calling the onclick method of a button on a separate web part to force a partial postback on the user.
Web Part A (Provider) calls a method in Web Part B (Consumer)
Web Part A
Type t = myButton.GetType (); object [] p = new object [1]; p [0] = EventArgs.Empty; MethodInfo m = t.GetMethod ("OnClick", BindingFlags.NonPublic | BindingFlags.Instance); m.Invoke (myButton, p);
Web Part B
public void btnHidden_Click (object sender, EventArgs e) {Label1.Text = "Hidden button:" + DateTime.Now.ToString (); }
When I use reflection, I get the correct information about the HiddenButton. However, I am unable to trigger the "OnClick" event. BtnHidden_Click fails. It works great when I call from WebPart B to WebPart B, but not from another website.
There seems to be too much information regarding this behavior. Any suggestions?
Thank.
Rob
Since the web parts need to be as flexible as possible, I would use the web part connection framework and subscriber pattern to handle this.
Communication between the connected parts takes place via an interface. This interface can include Subscribe and Unsubscribe methods. When the connection is made, the consumer can subscribe to any UpdatePanel controls that need to be updated when the selected item changes in the provider. Then, when the selected item changes, the provider part can move its subscribers and call the Update method on the UpdatePanel to force the async postback.
I haven't tried this myself, but the only drawback I see is that you might need to queue for Update calls, because any async postback initiation will override any other asynchronous callbacks that are currently running.
Hope this helps.
source to share
It's so incredibly easy to solve with JavaScript. I donβt mean to say that web parts are bad (to the extent that Iβve never worked with them), but I will say that if you can program the tiniest bit of JS in web parts, the code
document.getElementById('ElID').onclick();
Good luck!
source to share