How does one actually expose a abstracted event from asp.net usercontrol[ascx file] to the container webforms page. This is my scenario,
-
I created a webforms usercontrol a ascx file and put a databound checkboxlist with a validator to validate it(I know this could be done webforms itself why a usercontrol u ask, but it’s a scenario)
-
Now i wanted to expose a event to the container page called
OnValidatingwhich would produce the result of validation
signature of the event is below:
public delegate void Validating(object source,EventArgs e);
public event Validating OnValidating;
public void InvokeOnValidating(EventArgs e)
{
Validating handler = OnValidating;
if (handler != null) handler(this, e);
}
As per the msdn documentation, the page framework handles the event subscribing and unsubscribing. So all i need to do was invoke the event when validation fails. Great i was happy but,
-
I couldn’t show up the event in the properties window when all other public propertes did
-
Why the hell is my
event invoker[InvokeOnValidating],event delegate[Validating]shown in intellisense list when i typeusercontrolid.along with theevent[OnValidating]. I want only the event to be exposed. -
Also can i allow page to subscribe to event TextboxChanged created inside the usercontrol? If so get me the code.
Note: I would love to see more code than lengthy explanations
You’re mixing concepts, you don’t need a delegate to register events, try this code, and i’ll explain the changes and attempt to answer your questions below
On the page with the control use, notice the On, the framework adds this for all events:
Couldn’t add on comment, but basically if you need custom event args do as such: