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

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

本文关键字:第二次 运行 函数 选择器 UI 停止 日期      更新时间:2023-09-26

前端代码如下

 <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;
    }
}

所以我在这里面临的问题是代码实际上正在运行,但这是在它显示标签之后。我不能点击日期文本框,它使用日期选择器UI,在标签出现后不会显示日历。。。它还禁用了其他日期选择器文本框的js,这些文本框甚至与这些字段无关重要的问题是它停止了日期选择器UI,除非我刷新页面,否则这个代码本身不会再次运行。我希望能够检查其他可用的日期(如果没有)…所以请再次帮助我。。。提前感谢

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

顺便说一句,你也可以使用以下相同的:

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

你必须使用日期选择器类的文本框如下:

<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>