如何控制日期和时间格式?

我使用AJAX日历扩展程序在Date_Box中显示日期,然后使用数字向下扩展器选择时间。

代码如下:

<td bgcolor="#969ECD">
            &nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="Date_Box" runat="server" Width="85px"></asp:TextBox>&nbsp;

            <br />
             <div style="height: 4px"></div>

            &nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txtHour" runat="server" ></asp:TextBox>
            <ajaxToolkit:NumericUpDownExtender ID="txtHour_NumericUpDownExtender" 
                runat="server" Enabled="True" Maximum="12" Minimum="1"  
                TargetControlID="txtHour" Width="70" >    
            </ajaxToolkit:NumericUpDownExtender>

            <asp:TextBox ID="txtMinute" runat="server"></asp:TextBox>
            <ajaxToolkit:NumericUpDownExtender ID="txtMinute_NumericUpDownExtender" 
                runat="server" Enabled="True" Maximum="59" Minimum="1" 
                TargetControlID="txtMinute" Width="70" >
            </ajaxToolkit:NumericUpDownExtender>

            <asp:TextBox ID="txtDayPart" runat="server"></asp:TextBox>
            <ajaxToolkit:NumericUpDownExtender ID="txtDayPart_NumericUpDownExtender" 
                runat="server" Enabled="True" RefValues="AM;PM" TargetControlID="txtDayPart"  Width="70">
            </ajaxToolkit:NumericUpDownExtender>

            <asp:Button ID="Update" runat="server"  Text="Update" 
               onclick="Update_Click1" />
            <br />
        </td>
    </tr>
</table>
</div>

     <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" 
    TargetControlID="Date_Box" PopupPosition="TopRight"  >
     </ajaxToolkit:CalendarExtender>

从功能上来讲,现在唯一的问题是,当我在文本框中输入除常规格式以外的内容并单击“更新”按钮时,它允许我接受值,而不是除日期格式外不允许其他内容。我仍然可以使用一些异常消息找出答案,但现在的主要问题是控件的外观。数字扩展器按钮太大,行格式不好,三个时间文本框之间也有很多空格——有没有办法使它看起来整洁?

这是图片链接:http://www.freeimagehosting.net/image.php?05945773e0.jpg

The easiest thing to do is to assign your numeric extenders a CssClass property, and use css to fix the layout issues.

You can use asp:RegularExpressionValidator to validate textbox contents: http://msdn.microsoft.com/en-us/library/eahwtc9e.aspx

The documentation for NumericUpDown specifies you can use custom images for the updown buttons: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/NumericUpDown/NumericUpDown.aspx

You may want to try the FilteredTextbox from the ajax control kit found here. It will prevent typing into the box if they do not meet certain criteria. Hope this helps Tom