【问题标题】:Why does JQuery function returns undefined in update panel为什么 JQuery 函数在更新面板中返回未定义
【发布时间】:2020-02-12 21:29:20
【问题描述】:

我有这个禁用 srss 中的导出选项的 jquery 代码。

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
  $(document).ready(function() {
    hideOptions();
  });

  function hideOptions() {
    var MHTMLid = $("a[onclick=\"$find('ctl00_ContentPlaceHolder1_ReportViewerControl1_ReportViewer1').exportReport('PDF');\"]").parent().parent().attr("id");
    $("#" + MHTMLid + " div:nth-child(4)").css('display', 'none');
    console.log(MHTMLid);
  }
</script>

它应该搜索并隐藏 PDF 选项。问题是它适用于大多数页面,但无法更改更新面板中报告的显示选项。我的猜测是更新面板弄乱了 Jquery 操作。

您有什么建议。我无法从页面中删除更新面板。

【问题讨论】:

  • 你必须在异步回发之后再次执行hideOptions()。在这里查看我的答案:stackoverflow.com/a/45442175/5836671
  • 该代码应该放在哪里?我不明白你链接的答案@VDWWD
  • 请您将此作为答案,以便我将其标记为正确!谢谢您的帮助。效果很好

标签: javascript c# jquery asp.net reporting-services


【解决方案1】:

使用 UpdatePanel 时,您需要将 jQuery 重新绑定到 UpdatePanel 中的 DOM 元素,因为原始元素会因更新而丢失。

<script type="text/javascript">
    $(document).ready(function () {
        hideOptions();
    });

    var prm = Sys.WebForms.PageRequestManager.getInstance();

    prm.add_endRequest(function () {
        hideOptions();
    });

    function hideOptions() {
        var MHTMLid = $("a[onclick=\"$find('ctl00_ContentPlaceHolder1_ReportViewerControl1_ReportViewer1').exportReport('PDF');\"]").parent().parent().attr("id");
        $("#" + MHTMLid + " div:nth-child(4)").css('display', 'none');
        console.log(MHTMLid);
    }
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 2014-06-04
    • 2021-12-05
    相关资源
    最近更新 更多