部分回发后,更新面板中的 Javascript 不起作用 [英] Javascript in update panel doesn't work after partial postback

查看:27
本文介绍了部分回发后,更新面板中的 Javascript 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <script type="text/javascript">
        $(function () {
            $('.datePicker').datetimepicker({ dateFormat: 'dd/mm/yy' });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:TextBox ID="TextBox1" class="datePicker" runat="server"></asp:TextBox>
    <asp:UpdatePanel ID="holder" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
        <ContentTemplate>
            <asp:DropDownList runat="server" ID="ddl_RespondBy" AutoPostBack="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged">
                <asp:ListItem Selected="True">1 Hour</asp:ListItem>
                <asp:ListItem>Other</asp:ListItem>
            </asp:DropDownList>
            <asp:TextBox ID="txt_RespondBy" class="datePicker" Visible="true" runat="server" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddl_RespondBy" EventName="SelectedIndexChanged" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_RespondBy.SelectedItem.Text == "Other")
        {
            txt_RespondBy.Visible = true;
        }
        else
        {

        }
    }

我使用更新面板进行部分回发,我有两个文本框,一个在更新面板外面,一个在里面,当我从下拉列表中选择另一个并尝试打开 txt_RespondBy 文本框内的日历时,它不显示,但更新面板外的文本框显示日历.为什么 Javascript 在部分回发后无法在更新面板内工作

I do partial post back with the update panel, I have two text box one outside update panel and one inside, when I select other from the dropdown and try to open the calendar inside the txt_RespondBy text box it doesn't show, but the text box outside update panel shows the calendar. why is Javascript not working inside update panel after partial postback

推荐答案

将 datetimepicker 初始化代码放在 pageLoad 函数中,该函数在页面加载(异步或同步)时调用.

Place your datetimepicker initialisation code in the pageLoad function, which is called whenever the page loads (asynchronously or synchronously).

<script type="text/javascript">
    function pageLoad(sender, args) {
        $('.datePicker').datetimepicker({ dateFormat: 'dd/mm/yy' });
    }      
</script>

这篇关于部分回发后,更新面板中的 Javascript 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆