1

I call the following javascript function in an update panel which refresh my page although it is in an update panel!!

<script type="text/javascript" language="javascript">
    function get_emp_num(source, eventArgs) {
        var txt_emp_num = "<%= txt_RequestEmpNum.ClientID %>";
        document.getElementById(txt_emp_num).value = eventArgs.get_value();
        __doPostBack("<%=txt_RequestEmpNum.ClientID %>");
    }

    function get_person_num(source, eventArgs) {
        var txt_person_num = "<%= txt_RequestPersonNum.ClientID %>";
        document.getElementById(txt_person_num).value = eventArgs.get_value();
        __doPostBack("<%=txt_RequestPersonNum.ClientID %>");
    }

</script>

I don't want this script to change the partial post back behavior of my update panel .how to do that ?

4

2 回答 2

1

您的回发控件是什么,它是否设置为更新面板上的异步触发器?根据您发布的代码,我怀疑 txt_RequestEmpNum 和 txt_RequestPersonNum 是文本框。这些控件本身不支持回发。您需要的是页面上的隐藏按钮,您的 javascript 将“单击”以发送回发。像这样的东西:

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Button1" />
    </Triggers>
    <ContentTemplate>
        <asp:TextBox ID="txt_RequestEmpNum" runat="server" />
        <asp:TextBox ID="txt_RequestPersonNum" runat="server" />
    </ContentTemplate>
</asp:UpdatePanel>
<div style="display: none;">
    <asp:Button id="Button1" runat="server" OnClick="Button1_Click" />
</div>

<script>
    function get_emp_num(source, eventArgs) {
        // I am unsure what your intent was with the code here so I removed it
        __doPostBack("<%=Button1.UniqueID %>", "");
    }

    function get_person_num(source, eventArgs) {
        // I am unsure what your intent was with the code here so I removed it
        __doPostBack("<%=Button1.UniqueID %>", "");
    }

    function refresh_using_jquery() {
        __doPostBack($('#<%=Button1.ClientID %>').attr('name'), '');
    }
</script>
于 2013-02-26T19:14:10.137 回答
0

如果您不希望进行整页回发,那么您需要实现一个使用 AJAX 的解决方案。我会使用 jQuery,因为它使使用 AJAX 变得更容易(无论如何,在我看来)。

于 2013-02-26T17:05:07.513 回答