[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

update panel triggers with canlendar extender

Asked by mikolim in Programming for ASP.NET, .NET Framework 2.x

Tags: ASP.net

Hi experts,
i am making a leave application form formatted with html tables.
i have 2 text box  intended to capture the start date and end date of the leave application via calendar extender(ajax toolkit). I also have a label field which is intended to display the calculated numbers of day as the user input the date into the textbox using the calendar. I already have the functions that is able to calculate and change the value the label to reflect the calculated time span in terms of number of days.
i wish to be able to trigger an update to a label field when user input into textbox using calendar extender. for example when user input values into the textbox using the ajax calendar, it will be able to detect that something had been inputted into the textbox and call the function to calculate the number of days and update the label field. i am trying to use an update panel and set the triggers  to the 2 textbox but doesn't know the right way to do it, please provide assistance in c#.

Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
<table border="1" class="leave">          	
            <tr>
            	<th>Date Applied</th>
            	<td>
                    <asp:Label ID="lbl_dateApplied" runat="server"></asp:Label>
            	</td>
            </tr>
          	<tr>
            	<th>Leave Type</th>
                <td>
                    <asp:DropDownList ID="ddl_leaveType" runat="server">
                        <asp:ListItem Value="Annual" Selected= "True" >Annual</asp:ListItem>
                        <asp:ListItem Value="Medical" >Medical</asp:ListItem>
                        <asp:ListItem Value="Childcare" >Childcare</asp:ListItem>
                        <asp:ListItem Value="Maternity" >Maternity</asp:ListItem>
                        <asp:ListItem Value="Others" >Others</asp:ListItem>
                    </asp:DropDownList>                	
                </td>
            </tr>
            <tr>
            	<th>Employee Name</th>
            	<td>
            	    <asp:Label ID="lbl_employeeName" runat="server"></asp:Label>
            	</td>
            </tr>
            <tr>
            	<th>Department</th>
            	<td>
            	    <asp:Label ID="lbl_department" runat="server"></asp:Label>
            	</td>
            </tr>
            <tr>
            	<th>Start date</th>
            	<td>            	    
                    <asp:TextBox ID="tb_startDate" AutoPostBack="true" runat="server" 
                        ontextchanged="tb_startDate_TextChanged"></asp:TextBox>&nbsp;<asp:ImageButton 
                        ID="calendarIMG_1" CausesValidation="false" runat="server" 
                        ImageUrl="~/Pages/Images/calendar1.png" onclick="calendarIMG_1_Click" /><br/>                    
                    <asp:RequiredFieldValidator runat="server" id="rfv_startDate" controltovalidate="tb_startDate" errormessage="Enter Start Date!" />
                    <cc1:CalendarExtender ID="CalendarExtender1"  Enabled="true" TargetControlID="tb_startDate" format="MM dd yyyy" PopupButtonID="calendarIMG_1" runat="server">
                    </cc1:CalendarExtender>
                    <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" TargetControlID="tb_startDate" WatermarkCssClass="watermarked" WatermarkText="(mm dd yyyy)" runat="server">
                    </cc1:TextBoxWatermarkExtender><br/>                                                             
                    <asp:Label ID="lbl_errorMsg_startDate" runat="server" ForeColor="Red"></asp:Label>                                        
            	</td>
            </tr>        
            <tr>
            	<th>End date</th>
            	<td>                    
            	    <asp:TextBox ID="tb_endDate" AutoPostBack="true" runat="server"></asp:TextBox>&nbsp;<asp:ImageButton 
                        ID="calendarIMG_2" CausesValidation="false" runat="server" 
                        ImageUrl="~/Pages/Images/calendar2.png" onclick="calendarIMG_2_Click" /><br/>
            	    <asp:RequiredFieldValidator runat="server" id="rfv_endDate" controltovalidate="tb_endDate" errormessage="Enter End Date!" />
            	    <cc1:CalendarExtender ID="CalendarExtender2"  Enabled="true" TargetControlID="tb_endDate" format="MM dd yyyy" PopupButtonID="calendarIMG_2" runat="server">
                    </cc1:CalendarExtender>
                    <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender2" TargetControlID="tb_endDate" WatermarkCssClass="watermarked" WatermarkText="(mm dd yyyy)" runat="server">
                    </cc1:TextBoxWatermarkExtender><br/>                     
                    <asp:Label ID="lbl_errorMsg_endDate" runat="server" ForeColor="Red"></asp:Label>                    
            	</td>
            </tr>
            <tr>
            	<th>&nbsp;</th>
                <td>
                	<asp:DropDownList ID="ddlDateFromAmt" runat="server">
                        <asp:ListItem Value="0">Full Day</asp:ListItem>
                        <asp:ListItem Value="1">Half Day (AM)</asp:ListItem>
                        <asp:ListItem Value="2">Half Day (PM)</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
            	<th>No.Of Days</th>
            	<td>                    
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                    <asp:Label ID="lbl_numDays" runat="server"></asp:Label>            	
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="tb_startDate" 
                            EventName="TextChanged" />
                             <asp:AsyncPostBackTrigger ControlID="tb_enddate" 
                             EventName="TextChanged" />
                    </Triggers>
                    </asp:UpdatePanel>
            	</td>
            </tr>            
            <tr>
            	<th>Approver</th>
            	<td>
            	    <asp:Label ID="lbl_approver" runat="server"></asp:Label>
            	</td>
            </tr>
            <tr>
            	<th>Remarks<br/>(optional)</th>
            	<td>
                    <asp:TextBox ID="tb_remarks" runat="server" Columns="30" Rows="10" TextMode="MultiLine"></asp:TextBox>                    
                </td>            	
            </tr>            
          </table>
 
code behind
============
//funtion that will calculate the number of days and reflect the value in the label
protected void CalculateNumberOfDays()
    {
        DateTime startTime, endTime;
 
        if (DateTime.TryParse(tb_startDate.Text.ToString(), out startTime) == false)
        {
 
            lbl_errorMsg_startDate.Text = "Please select a valid start date.";
 
            return;
 
        }
 
        if (DateTime.TryParse(tb_endDate.Text.ToString(), out endTime) == false)
        {
 
            lbl_errorMsg_endDate.Text = "Please select a valid end date.";
 
            return;
 
        }
 
        if (DateTime.Compare(startTime, endTime) > 0)
        {
 
            lbl_errorMsg_startDate.Text  = "Please select a valid date range.";
            lbl_errorMsg_endDate.Text =  "Please select a valid date range.";
 
            return;
 
        }
 
        if (int.Parse(ddlDateFromAmt.SelectedValue.ToString()) == 0)
        {           //reflect the calculated num of days to the label
            lbl_numDays.Text = Weekdays(startTime, endTime).ToString();
 
        }
        else
        {                    
 
            lbl_numDays.Text = Weekdays(startTime).ToString();
 
        }
    }
 
    int Weekdays(DateTime dtmStart, DateTime dtmEnd)
    {
 
        try
        {
 
            // This function includes the start and end date in the count if they fall on a weekday
 
            int dowStart = ((int)dtmStart.DayOfWeek == 0 ? 7 : (int)dtmStart.DayOfWeek);
 
            int dowEnd = ((int)dtmEnd.DayOfWeek == 0 ? 7 : (int)dtmEnd.DayOfWeek);
 
            TimeSpan tSpan = dtmEnd - dtmStart;
 
            if (dowStart <= dowEnd)
            {
 
                return (((tSpan.Days / 7) * 5) + Math.Max((Math.Min((dowEnd + 1), 6) - dowStart), 0));
 
            }
 
            else
            {
 
                return (((tSpan.Days / 7) * 5) + Math.Min((dowEnd + 6) - Math.Min(dowStart, 6), 5));
 
            }
 
        }
 
        catch (Exception ex)
        {
 
            throw new Exception(ex.Source.ToString() + ":" + ex.Message.ToString() + ":" + ex.InnerException.ToString());
 
        }
 
    }
 
    double Weekdays(DateTime dtmStart)
    {
 
        try
        {
 
            // This function includes the start if they fall on a weekday
 
            if ((int)dtmStart.DayOfWeek == 6 || (int)dtmStart.DayOfWeek == 7)
 
                return 0.0;
 
            else
 
                return 0.5;
 
        }
 
        catch (Exception ex)
        {
 
            throw new Exception(ex.Source.ToString() + ":" + ex.Message.ToString() + ":" + ex.InnerException.ToString());
 
        }
 
 
 
    }
 
Related Solutions
Keywords: update panel triggers with canlendar e…
 
Loading Advertisement...
 
[+][-]10/12/09 09:56 AM, ID: 25552831Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 09:57 AM, ID: 25552839Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 10:52 AM, ID: 25553386Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Programming for ASP.NET, .NET Framework 2.x
Tags: ASP.net
Sign Up Now!
Solution Provided By: jazz__man
Participating Experts: 2
Solution Grade: A
 
[+][-]11/12/09 05:57 PM, ID: 25810778Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625