c# - display time in a textbox and modify with up down arrows -
i want display time in textbox or in numericupdownextender used in ajax user can change time desires..
i have used control show numbers , increase accordingly..
is there way this..
new code not desired...
<asp:textbox runat="server" id="txthour"></asp:textbox> <ajaxtoolkit:numericupdownextender id="txthour_numericupdownextender" runat="server" enabled="true" maximum="12" minimum="1" targetcontrolid="txthour" width="70"></ajaxtoolkit:numericupdownextender> <asp:textbox runat="server" id="txtminute"></asp:textbox> <ajaxtoolkit:numericupdownextender id="txtminute_numericupdownextender" runat="server" enabled="true" maximum="60" minimum="1" targetcontrolid="txtminute" width="70"></ajaxtoolkit:numericupdownextender> <asp:textbox runat="server" id="txtdaypart"></asp:textbox> <ajaxtoolkit:numericupdownextender id="txtdaypart_numericupdownextender" runat="server" enabled="true" refvalues="am;pm" targetcontrolid="txtdaypart" width="70"></ajaxtoolkit:numericupdownextender>
the code behind is:
private void parsetime(string timestring) { // validation of input if (timestring.indexof(":") == -1) { return; } if ((timestring.indexof("pm") == -1) && (timestring.indexof("am") == -1)) { return; } // go format int colonpos = timestring.indexof(":"); int ampos = timestring.indexof("am"); int pmpos = timestring.indexof("pm"); string shour = timestring.substring(0, colonpos); string sminutes = timestring.substring(colonpos, 3); string sdaypart = (timestring.indexof("am") != -1) ? timestring.substring(ampos, 2) : timestring.substring(pmpos, 2); txthour.text = shour; txtminute.text = sminutes; txtdaypart.text = sdaypart; }
yes should pretty simple achieve using updownextender. attach web service methods serviceupmethod , servicedownmethod increment/decrement datetime required timespan. haven't posted code it's difficult know stuck.
update: ok, having thought this, don't think there real reason use updownextender server call backs. quick google discovered javascript has basic date manipulation functions, it's easy enough client side.
i'm not javascript expert, following code possibly of questionable quality, seems work ok , set on right track. let me know if still stuck.
<head runat="server"> <title></title> <script type="text/javascript" language="javascript"> <!-- var date; function initdateobject() { date = new date ( "january 1, 2000 12:00:00" ); showtimeportion(); } function showtimeportion() { document.getelementbyid('timedisplay').value = padtominimumlength(date.gethours(),2) + ':' + padtominimumlength(date.getminutes(),2) + ':' + padtominimumlength(date.getseconds(),2); } function padtominimumlength(number, requiredlength) { var pads = requiredlength - (number + '').length; while (pads > 0) { number = '0' + number; pads--; } return number; } function addminutes(n) { date.setminutes(date.getminutes() + n); showtimeportion(); } function settodaystime() { var d = new date(); d.sethours(date.gethours()); d.setminutes(date.getminutes()); d.setseconds(date.getseconds()); alert('the time ' + d.tostring()); } --> </script> </head> <body onload="initdateobject();"> <form id="form1" runat="server"> <div> <input type="text" id="timedisplay" readonly="readonly"/> <a href="#" onclick="addminutes(1)">+</a> <a href="#" onclick="addminutes(-1)">-</a> <br /> <a href="#" onclick="settodaystime()">submit</a> </div> </form> </body>
Comments
Post a Comment