2017-08-04 125 views
0

我的web应用程序中有一个用作日期选择器的输入文本字段。 在按钮的单击事件上,表单中的数据将得到验证,如果任何条件失败,用户将收到警报。保留输入文本字段的值asp.net

<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
    <script> 
     $(function() { 
      $("#datepicker1").datepicker(); 
     }); 
</script> 
<input type="text" name="startDate" id="datepicker1" /> 
<asp:Button runat="server" OnClick="btnSubmit_Click" ID="btnSubmit" Text="Submit" /> 

这里的问题是,如果数据无效,输入字段的值不会保留。我试图使用“datepicker1.Value”设置值,但这不起作用。请给我一个解决方案。

回答

1

在使用RUNAT =“server”属性,以我的输入型不允许的日期选择器日历出现添加RUNAT =“server”属性输入型

<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
    <script> 
     $(function() { 
      $("#datepicker1").datepicker(); 
      //or 
      // $(".datepicker").datepicker(); 
     }); 
</script> 
<input type="text" class="datepicker" name="startDate" runat="server" id="datepicker1" /><asp:Button runat="server" OnClick="btnSubmit_Click" ID="btnSubmit" Text="Submit" /> 
+0

。 –

+0

你可能已经添加了母版页,如果是这样的话,那么id将会被改变,而页面被赋予浏览器,所以而不是像下面这样的使用类 Yogesh

+0

谢谢。在使用课堂时,我能够保留这个价值。 :) –