日期选择器 UI 停止并且函数不会 运行 第二次

the datepicker UI stops and the function wont run the second time

前端代码如下

 <div id="dvRecWed" style="display: none">
                    <asp:UpdatePanel ID="PnlUsrDetails" runat="server">
                        <ContentTemplate>
                            <table>
                                <tr>
                                    <td>Reception Date</td>
                                    <td>
                                        <asp:TextBox ID="txtReceptionDate" runat="server"></asp:TextBox>
                                    </td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td>Reception Time</td>
                                    <td>
                                        <asp:DropDownList AutoPostBack="true" ID="ddlReceptionTime" runat="server" OnSelectedIndexChanged="txtUsername_TextChanged">
                                            <asp:ListItem>--Select--</asp:ListItem>
                                            <asp:ListItem Value="Forenoon">Forenoon</asp:ListItem>
                                            <asp:ListItem Value="Afternoon">Afternoon</asp:ListItem>
                                            <asp:ListItem Value="FullDay">Full Day</asp:ListItem>

                                        </asp:DropDownList>
                                    </td>
                                    <td>
                                        <div id="checkdate" class="checkdate" runat="server" visible="false">
                                            <asp:Image ID="imgstatus" runat="server" Width="17px" Height="17px" />
                                            <asp:Label ID="lblStatus" runat="server"></asp:Label>
                                        </div>
                                    </td>
                                </tr>

我的后端代码是

protected void txtUsername_TextChanged(object sender, EventArgs e)
{

    if (!string.IsNullOrEmpty(ddlReceptionTime.Text))
    {
        string connString = ConfigurationManager.ConnectionStrings["MandapamDatabase"].ConnectionString;
        OleDbConnection connection = new OleDbConnection(connString);
        // SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName=@Name", con);
        string selectQuery = "SELECT FunctionTime FROM function WHERE FunctionDate=@FunctionDate AND FunctionTime='FullDay'";
        connection.Open();
        OleDbCommand command = new OleDbCommand(selectQuery, connection);
        command.Connection = connection;
        command.CommandText = selectQuery;
        command.CommandType = CommandType.Text;
        command.Parameters.AddWithValue("@FunctionDate", txtReceptionDate.Text);
        command.Parameters.AddWithValue("@FunctionTime", ddlReceptionTime.Text);
        OleDbDataReader dr = command.ExecuteReader();
        if (dr.HasRows)
        {
            checkdate.Visible = true;
            imgstatus.ImageUrl = "~/img/cross.png";
            lblStatus.Text = "Date Unavailable";
            lblStatus.ForeColor = System.Drawing.Color.Red;
        }
        else
        {
            checkdate.Visible = true;
            imgstatus.ImageUrl = "~/img/check.png";
            lblStatus.Text = "Date available";
        }
    }




    else if (!string.IsNullOrEmpty(ddlReceptionTime.Text))
    {
        string connString = ConfigurationManager.ConnectionStrings["MandapamDatabase"].ConnectionString;
        OleDbConnection connection = new OleDbConnection(connString);
        // SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName=@Name", con);
        string selectQuery = "SELECT FunctionTime FROM function WHERE FunctionDate=@FunctionDate AND FunctionTime=@FunctionTime";
        connection.Open();
        OleDbCommand command = new OleDbCommand(selectQuery, connection);
        command.Connection = connection;
        command.CommandText = selectQuery;
        command.CommandType = CommandType.Text;
        command.Parameters.AddWithValue("@FunctionDate", txtReceptionDate.Text);
        command.Parameters.AddWithValue("@FunctionTime", ddlReceptionTime.Text);
        OleDbDataReader dr = command.ExecuteReader();
        if (dr.HasRows)
        {
            checkdate.Visible = true;
            imgstatus.ImageUrl = "~/img/cross.png";
            lblStatus.Text = "Date Unavailable";
            lblStatus.ForeColor= System.Drawing.Color.Red;

        }
        else
        {
            checkdate.Visible = true;
            imgstatus.ImageUrl = "~/img/check.png";
            lblStatus.Text = "Date Available";
        }
    }
    else
    {
        checkdate.Visible = false;
    }
}

所以我在这里面临的问题实际上是代码 运行s 但在它显示标签后就是这样 我无法点击使用日期选择器 UI 的日期文本框不会显示标签出现后的日历...它也禁用其他甚至不关心这些字段的日期选择器文本框的 js 重要的问题是它停止了日期选择器 UIs 并且此代码本身不会再次 运行 除非我刷新页面我希望能够检查其他可用日期(如果没有) ...所以请再次帮助我...提前致谢

因为我在您的问题中看不到任何日期选择器代码,并且假设您使用的是相同的 jquery ui 日期选择器。

顺便说一下,您也可以使用以下相同的方法:

function jScript() {
        $(document).ready(function () {
            $('.datepicker').datepicker({
                dateFormat: "dd/M/yy",
                changeMonth: true,
                changeYear: true,
                yearRange: '1950:' + new Date().getFullYear().toString()
            });
        });
    }

您必须为如下文本框使用日期选择器class:

<asp:TextBox class="form-control" autocomplete="off" ID="txtdate" CssClass="datepicker"
                                    placeholder="mm/dd/yy" runat="server"></asp:TextBox>   

现在每次页面加载后初始化日期选择器,你必须使用下面的代码,基本上它每次都会加载上面的函数。

 <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript" language="javascript">
    Sys.Application.add_load(jScript);    
</script>

请根据此更新您的代码,可能会有帮助。

这可能是由于您在表单中使用的更新面板所致。在这种情况下,您必须在主页文件中添加以下代码。

所有 jquery 需要在异步回发调用时重新加载,应在以下函数中添加。

<script type="text/javascript">
    function pageLoad() {
        $.getScript('MY_UTILITY_SCRIPT.js', function () {
        });
    }
  </script>