2017-08-04 116 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

謝謝。在使用課堂時,我能夠保留這個價值。 :) –