User Control Page /MobileModules/Contacts.ascx (C#)
1: <%@ Control Language="C#" Inherits="ASPNetPortal.MobilePortalModuleControl" Debug="true" %>
2: <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
3: <%@ Register TagPrefix="portal" TagName="Title" Src="~/MobileModuleTitle.ascx" %>
4: <%@ Register TagPrefix="portal" Namespace="ASPNetPortal.MobileControls" Assembly="Portal" %>
5: <%@ Import Namespace="System.Data" %>
6:
7: <%--
8:
9:     The Contacts Mobile User Control renders Contacts modules in the
10:     mobile portal.  
11:
12:     The control consists of two pieces: a summary panel that is rendered when
13:     portal view shows a summarized view of all modules, and a multi-part panel  
14:     that renders the module details.
15:
16: --%>
17:
18: <script runat="server">
19:
20:     DataSet ds = null;
21:     int currentIndex = 0;
22:     
23:     //*********************************************************************  
24:     //  
25:     // Page_Load Event Handler  
26:     //  
27:     // The Page_Load event handler on this User Control is used to  
28:     // obtain a DataSet of contact information from the Contacts  
29:     // database, and then databind the results to the module contents.  
30:     //  
31:     //*********************************************************************  
32:     
33:     void Page_Load(Object sender, EventArgs e) {
34:     
35:         // Obtain announcement information from Contacts table  
36:         ASPNetPortal.ContactsDB ct = new ASPNetPortal.ContactsDB();
37:         ds = ct.GetContacts(ModuleId);
38:
39:         // DataBind User Control  
40:         DataBind();
41:     }
42:                   
43:     //*********************************************************************  
44:     //  
45:     // SummaryView_OnClick Event Handler  
46:     //  
47:     // The SummaryView_OnClick event handler is called when the user  
48:     // clicks on the link in the summary view. It shows the list of  
49:     // contacts.  
50:     //  
51:     //*********************************************************************  
52:
53:     void SummaryView_OnClick(Object sender, EventArgs e) {
54:     
55:         // Switch the visible pane of the multi-panel view to show  
56:         // the list of contacts.  
57:         MainView.ActivePane = ContactsList;
58:
59:         // Make the parent tab switch to details mode, showing this module.  
60:         Tab.ShowDetails(this);
61:     }
62:
63:     //*********************************************************************  
64:     //  
65:     // ContactsList_OnItemCommand Event Handler  
66:     //  
67:     // The ContactsList_OnItemCommand event handler is called when the user  
68:     // clicks on a contact in the contact list. It shows the details of the  
69:     // contact.  
70:     //  
71:     //*********************************************************************  
72:
73:     void ContactsList_OnItemCommand(Object sender, ListCommandEventArgs e) {
74:     
75:         currentIndex = e.ListItem.Index;
76:         ContactDetails.DataBind();
77:
78:         // Switch the visible pane of the multi-panel view to show  
79:         // contact details.  
80:         MainView.ActivePane = ContactDetails;
81:             
82:         // rebind the details panel  
83:         ContactDetails.DataBind();
84:     }
85:
86:     //*********************************************************************  
87:     //  
88:     // DetailsView_OnClick Event Handler  
89:     //  
90:     // The DetailsView_OnClick event handler is called when the user  
91:     // clicks on a link in the contact details view to return to the  
92:     // list of contacts.  
93:     //  
94:     //*********************************************************************  
95:
96:     void DetailsView_OnClick(Object sender, EventArgs e) {
97:     
98:         ContactsList.DataBind();
99:
100:         // Switch the visible pane of the multi-panel view to show  
101:         // the list of contacts.  
102:         MainView.ActivePane = ContactsList;
103:     }
104:
105:
106:     //*********************************************************************  
107:     //  
108:     // GetPhoneNumber Method  
109:     //  
110:     // The GetPhoneNumber method extracts a phone number from a contact  
111:     // entry, if possible, using a regular expression search.  
112:     //  
113:     //*********************************************************************  
114:
115:     private String GetPhoneNumber(String s) {
116:     
117:         if (s != String.Empty) {
118:         
119:             // Look for a phone number.  
120:             Match phoneMatch = Regex.Match(s, "\\+?[\\d\\(\\)\\.-]+");
121:             s = phoneMatch.Success ? phoneMatch.ToString() : String.Empty;
122:         }
123:
124:         return s;  
125:     }
126:
127:     //*********************************************************************  
128:     //  
129:     // FormatChildField Method  
130:     //  
131:     // The FormatChildField method returns the selected field as a string,  
132:     // if the row is not empty.  If empty, it returns String.Empty.  
133:     //  
134:     //*********************************************************************  
135:
136:     string FormatChildField (string fieldName) {
137:     
138:         if (ds.Tables[0].Rows.Count > 0)  
139:             return ds.Tables[0].Rows[currentIndex][fieldName].ToString();
140:         else
141:             return String.Empty;
142:     }            
143:
144: </script>
145:
146: <mobile:Panel runat="server" id="summary">
147:     <DeviceSpecific>
148:         <Choice Filter="isJScript">
149:             <ContentTemplate>
150:                 <portal:Title runat="server" />
151:                 <font face="Verdana" size="-2">Click <a runat="server" OnServerClick="SummaryView_OnClick">
152:                         here</a> to access the directory of contacts. </font>
153:                 <br>
154:             </ContentTemplate>
155:         </Choice>
156:     </DeviceSpecific>
157: </mobile:Panel>
158:
159: <portal:MultiPanel runat="server" id="MainView" Font-Name="Verdana" Font-Size="Small">
160:
161:     <portal:ChildPanel id="ContactsList" runat="server">
162:         <portal:Title runat="server" />
163:         <mobile:List runat="server" OnItemCommand="ContactsList_OnItemCommand" DataTextField="Name" DataSource="<%# ds %>">
164:             <DeviceSpecific>
165:                 <Choice Filter="isJScript">
166:                     <HeaderTemplate>
167:                         <table width="95%" border="0" cellspacing="0" cellpadding="0">
168:                     </HeaderTemplate>
169:                     <ItemTemplate>
170:                         <tr>
171:                             <td>
172:                                 <font face="Verdana" size="-2"><a href='<%# "mailto:" + DataBinder.Eval(((MobileListItem)Container).DataItem, "Email") %>'>
173:                                         <%# DataBinder.Eval(((MobileListItem)Container).DataItem, "Name") %>
174:                                     </a></font>
175:                             </td>
176:                             <td align="right">
177:                                 <font face="Verdana" size="-2">
178:                                     <asp:LinkButton runat="server" Text="more" />
179:                                 </font>
180:                             </td>
181:                         </tr>
182:                     </ItemTemplate>
183:                     <FooterTemplate>
184:                         </table>
185:                     </FooterTemplate>
186:                 </Choice>
187:             </DeviceSpecific>
188:         </mobile:List>
189:     </portal:ChildPanel>
190:     
191:     <portal:ChildPanel id="ContactDetails" runat="server">
192:         <portal:Title runat="server" Text='<%# FormatChildField("Name") %>' />
193:         <b>Role: </b>
194:         <mobile:Label runat="server" Text='<%# FormatChildField("Role") %>' />
195:         <b>Email: </b>
196:         <mobile:Link runat="server" NavigateUrl='<%# "mailto:" + FormatChildField("Email") %>' Text='<%# FormatChildField("Email") %>' />
197:         <b>Contacts: </b>
198:         <br>
199:         <mobile:PhoneCall runat="server" Visible='<%# FormatChildField("Contact1") != String.Empty %>' PhoneNumber='<%# GetPhoneNumber(FormatChildField("Contact1")) %>' Text='<%# FormatChildField("Contact1") %>' AlternateFormat="{0}" />
200:         <mobile:PhoneCall runat="server" Visible='<%# FormatChildField("Contact2") != String.Empty %>' PhoneNumber='<%# GetPhoneNumber(FormatChildField("Contact2")) %>' Text='<%# FormatChildField("Contact2") %>' AlternateFormat="{0}" />
201:         <portal:LinkCommand runat="server" OnClick="DetailsView_OnClick" Text="back to list" />
202:     </portal:ChildPanel>
203:     
204: </portal:MultiPanel>