Pages

Ads 468x60px

Labels

Wednesday, February 13, 2013

User Control 3






 That is CX here's stateless.ASC X and here is footer.ASC X would define the layout of this page in a way that we can reuse on multiple pages within the site and we started using a user control now going to look at a more complex user control this user control provides a list of states and how often have you built a page.

 Where you need to provide a list of states for your country I'll be using the United States but I'm sure every developer has done this for his or her own locale this control needs to allow you to support auto post back so that choosing estate will trigger some event automatically it needs to provide text and value properties you can look at one view of the state name and perhaps return a different one either show you the short name and return the long name or show you the long name and return the short name.

 It needs to raise the selected index changed event you can react to the event were the user selects a state offices been done for you were going to look at state list.ASC X in the sample project another data has to come from somewhere and we could use XML file or database but a static data we haven't added ministate store list of states a long time so this is hardcoded is actually provided in the control itself the user control needs to provide some properties for example.

 It needs an auto post back Boolean property it needs a text property and it needs of value property will investigate each of these in the code for the control finally the control needs to raise events will declare the event and then raise it when necessary let's step back and look at the state list user control over the completed.aspx page into the browser so we can investigate the behavior of the drop-down list here's our state drop-down list and it displays a list of the United States the long names if I choose one it's short name appears in this text box there must be some event that occurs my select one and we retrieve.

The value of the drop-down list and place the value in this text box there is also the ability to set the value suffice set this to a state and click set value it sets the value of this list so you can see we can retrieve the value when the user makes a selection and set the value based on some external event while that's pretty much all this thing does not too exciting but it does satisfy a need that is it encapsulates some commonly used functionality lets look at the source code to see how it works here we have state list.ASC X and all view the designer first well it's a drop-down list that spirit not much here but what needs to be the output of this drop-down list and it shows before was run.

0 comments:

Post a Comment

 

Sample text

Sample Text

Total Pageviews