我的应用程序在asp.net 3.5中,我从更新面板内的日期选择器中选择日期。选择日期并点击提交按钮页面后回复。回帖后,当我再次尝试选择日期时,我在那里看不到日期选择器。
// aspx页面上的代码
<%@ Page Title="" Language="C#" MasterPageFile="~/Sample/MasterPage.master" AutoEventWireup="true" CodeFile="UpdateProblem.aspx.cs" Inherits="Sample_UpdateProblem" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript" src="jscolor/jscolor.js"></script> // Script for date
<asp:ScriptManager ID="ScriptManager1" runat="server" >
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="panel1" runat="server">
<ContentTemplate>
<asp:TextBox runat="server" ID="textbox" CssClass="color" />
<asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>
提前致谢
答案 0 :(得分:7)
在您的UpdatePanel中,在测试框上添加css类
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" CssClass="classTarget"></asp:TextBox>
.....
</ContentTemplate>
</asp:UpdatePanel>
在您的脚本中添加此代码
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
$('.classTarget).datepicker({ dateFormat: 'dd-mm-yy' });
}
});
</script>
答案 1 :(得分:0)
$(function () {
bindDatePickers(); // bind date picker on first page load
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindDatePickers); // bind date picker on every UpdatePanel refresh
});
function bindDatePickers() {
$('#<%= txtInvoiceDateFrom.ClientID%>').datepicker({
uiLibrary: 'bootstrap4'
});
$('#<%= txtInvoiceDateTo.ClientID%>').datepicker({
uiLibrary: 'bootstrap4'
});
}