Pages

Ads 468x60px

Labels

Sunday, February 17, 2013

User Control 5




 More thought event handler is a little higher up here we are and it's the selected index changed event would like to expose or raise from this user control what I need to do is declare a public event selected index changed I can call it whatever I want but it certainly is more polite to name it something that's familiar to the user or the consumer of this control and that would be selected index changed every defined event in.net has a well-known or fixed signature in this case.
This event handler needs to receive sender as object and be as event darks five declared my event that way I declare the event that I'm going to raise and here in the selected index changed event of my private drop-down list that is inside the control all of you to do is raise the event back out to whoever's listening that is whoever has consumed this control this is how you raise an event from within a user control you receive the event you care about in this case the selected index changed event of the drop-down list of inside the user control and then.

 You raise an event which corresponds to what you want the consumer of your control to see otherwise they can't receive any events of the drop-down list that's embedded inside your user control this isn't a good example of this because our user control contains only a single wheel control if there were multiple controls this would be more obvious because of their multiple controls how would the user control know how to map internal events to external events and so were required to raise this event to the outside world and I'm raising the selected index change that I just defined here passing me that is the user control and be whatever got passed to me here and those are passed out to the consumer of this control.

 Well that's all the code there is so let's look at the completed page to see how it handles the events of this user control here's the user control and you can see that I will see the events here at all on the properties window but if I go into the code window I should be able to go to state list one and five it selected index changed event all these other events listed here those are events that are exposed by the user control container notice there are no other events of a drop-down list exposed here because I did expose and all these other events, for every user control they all get them for free my selected index changed event I've handled by taking the value of the state list and placing it into the text of the text box of course I also have code that takes the text of the text box and shoves it into the value of the state list when I do that I sent the value is the list.


0 comments:

Post a Comment

 

Sample text

Sample Text

Total Pageviews