首页 > 解决方案 > Textbox readonly property makes whole group readonly during implementation of datatime picker

问题描述

I am trying implement bootstrap datetime picket in my asp.net application. I have written the following code to display the datetime picker.

<div class="input-group date" data-provide="datetimepicker1">   
    <asp:TextBox ID="txtDateTime" runat="server" class="form-control" placeholder="Date Time" ReadOnly="true"></asp:TextBox>
<span class="input-group-addon">    
    <span class="glyphicon glyphicon-calendar"></span>
<span>
    <i class="glyphicon glyphicon-remove"></i>
</span>
</span>
</div> 

I want to make the textbox, i.e., #txtDateTime readonly because I want to avoid validation regarding date and time. But when I make readonly property "True", everything becomes read only including the <span> that contain glyphicon glyphicon-calendar. How can I make only the textbox readonly.

Thanks Partha

标签: htmlasp.nettwitter-bootstrap

解决方案


不确定您在只读跨度中的意思,无论如何您可以覆盖onkeydown输入控件上的事件,这将是一个安全的解决方案,与您的解决方案一样与服务器端控件无关。

<input onkeydown="return false"  />

在你的例子中试试这个:

<asp:TextBox ID="txtDateTime" runat="server" class="form-control" placeholder="Date Time" onkeydown="return false"></asp:TextBox>

推荐阅读