views:

17

answers:

1

Is there a client side event that occurs on a user control when its parent submits to the server?

A: 

No I don't think there is something that will automatically trigger client side in your user control. I have implemented something similar to this in the past by including some client script function from my user control and then manually calling it in the OnClientClick of the asp:Button.

The only problem with this solution is that it is not 'automatic' and whatever page is using your user control will have to know to implement it. Also depending on your case capturing all types of 'submits' (assuming you mean PostBack as well) might be a little cumbersome.

Kelsey
The exact problem I am hoping to avoid is having to implement this on all pages the control is used on. I still have hope that someone out there has a way to do it! :)
Ashley
Could you implement the necessary functionality in the control's codebehind? Perhaps in its Load() function, within an if (isPostback) block? That would require no additional code on the the parent page. Of course, the control's Load() function isn't "client-side" behavior.
mikemanne
Nope sadly I cannot...I have a listbox that gets populated dynamically. Dynamically added items dont get added to viewstate so to avoid having to store the list items in a hidden field I woulod like to just cause all options to be selected before the parent submits. Selected options can be accessed using Request.Form["yourListBox"].
Ashley
I understand. Viewstate is a common point of difficulty when implementing a site that uses some purely client-side/js dynamic content and some postback-based dynamic content. FWIW, I would go with the hidden field. It isn't pretty, but at least it is encapsulated purely within the control itself.
mikemanne
@Ashley have you considered adding an `$("#yourForm").submit(function () {...` to your user control. Not sure what that will do with the postback behavior but it might at least get going in the right direction.
Kelsey