c# - Date / time control asp.net -


i have webform app calculates time difference between 2 dates , give in format number of days, total hours, total mins.

my markup code following:

<asp:label id="label20" runat="server" cssclass="label">resolved date</asp:label> <asp:textbox id="textbox14" runat="server" cssclass="textbox"      textmode="date" ontextchanged="textbox14_textchanged"></asp:textbox> 

now ontextchanged event calculate time difference date time textbox.

i have done this:.

protected void textbox14_textchanged(object sender, eventargs e) {     // date first text box      datetime dold = convert.todatetime(textbox1.text);     datetime dnew = convert.todatetime(textbox14.text);     timespan daydif = (dnew - dold);     double dayd = daydif.totaldays;     label27.text = dayd.tostring(); } 

my problem whenever there no output it? label27 not have diff of days values.

is there other event trigger not aware of?

thanks help.

i agree jon skeet use calendar controls purpose, run input validation problems text field, calendar working date object. first can add calendar fields page.

<!-- old date --> <asp:calendar id="calendar1" runat="server"></asp:calendar> <!-- new date --> <asp:calendar id="calendar2" onselectionchanged="textbox14_textchanged" runat="server"></asp:calendar> 

then in onchanged method can calculate timespan in 1 line, no sense in creating object double hold total days when can access so. unless going use many places perhaps create holder double.

protected void textbox14_textchanged(object sender, eventargs e)     {         //might add quick validation make sure date selected in both calendars.         // not sure if subtracting old new or new old can sorta out         label20.text = ((timespan)(calendar2.selecteddate - calendar1.selecteddate)).totaldays.tostring();     } 

keep in mind when onselection changed called page being refreshed cause data has submitted page in order server side processing happen. web page events not work winforms.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -