使用 jquery 更改按钮的可见性 - UpdatePanel

发布于 2024-12-13 15:07:44 字数 2532 浏览 0 评论 0原文

我有 2 个按钮(过滤器和查看摘要)和一个更新面板。更新面板包含网格。单击过滤器按钮时 - 将从数据库中获取数据并触发更新面板。现在,根据数据的内容,我想更改视图摘要按钮的可见性。

我已经尝试过 - hfSummaryVis 是我在更新面板中设置的隐藏字段

function pageLoad() {
    alert('<%=hfSummaryVis.Value %>');
}

警报消息始终为空。我也尝试过 document.ready。 Document.Ready 仅在页面首次加载时调用。

请帮忙

谢谢,

<div id="divOrderDateSelector" class="FloatLeft PadDiv" style="padding-top: 3px;">
  <asp:Button ID="btnFilter" runat="server" Text="Filter" 
    OnClick="btnFilter_Click" CssClass="DefaultButton"/>
  <asp:Button ID="btnSummary" runat="server" Text="View Summary"
    OnClick="btnSummary_Click" CssClass="DefaultButton" 
    onclientclick="return false"/>
</div>
<br/>
<div id="divbuy" class="ClearBoth PadBottom">
  <span class="SectionHeader Block" >Buys</span>  
    <asp:UpdatePanel ID="upStatus" runat="server" UpdateMode="Conditional" >
      <Triggers >
        <asp:AsyncPostBackTrigger ControlID="btnFilter" EventName="Click"/>
      </Triggers>
      <ContentTemplate >
        <asp:HiddenField ID="hfSummaryVis" runat="server" />
        <asp:GridView ID="gvSummary" runat="server" AutoGenerateColumns="False" 
          CssClass="ContrastTable WideTable" GridLines="None" 
          onrowdatabound="gvSummary_RowDataBound">
          <EmptyDataTemplate>No Records Found</EmptyDataTemplate>
          <RowStyle CssClass="MainTableRow" />
          <AlternatingRowStyle CssClass="AlternateRow" />
          <HeaderStyle CssClass="HeaderRow" />
          <Columns>
            <asp:TemplateField>
              <ItemTemplate>
                <asp:LinkButton ID="lkBtnOpen" runat="server" CssClass="Expand ButtonCell PlainLink"  
                  ToolTip="Click to see details of the date's orders."
                  Text="&nbsp;&nbsp;&nbsp;" OnClientClick="showCusipAccountDetails(" />
                <asp:LinkButton ID="lkBtnClose" runat="server" CssClass="Collapse ButtonCell PlainLink Hidden"
                  ToolTip="Click to close." 
                  Text="&nbsp;&nbsp;&nbsp;" />
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Strategy Series">
              <ItemTemplate>
                <asp:Label ID="lblStrategySeries" runat="server" />
              </ItemTemplate>
            ...

I have 2 buttons (Filter and view summary) and a updatepanel. The update panel hold the grid. When the filter button is clicked - the data is fetched from the database and the updatepanel is triggered. Now based on the contents of the data, i want to change the visibility of the view summary button.

I have tried - hfSummaryVis is the hiddenfield that i set in the update panel

function pageLoad() {
    alert('<%=hfSummaryVis.Value %>');
}

The alert message is always blank . I have also tried document.ready. Document.Ready is only called when the page loads for the first time.

Please help

Thanks,

<div id="divOrderDateSelector" class="FloatLeft PadDiv" style="padding-top: 3px;">
  <asp:Button ID="btnFilter" runat="server" Text="Filter" 
    OnClick="btnFilter_Click" CssClass="DefaultButton"/>
  <asp:Button ID="btnSummary" runat="server" Text="View Summary"
    OnClick="btnSummary_Click" CssClass="DefaultButton" 
    onclientclick="return false"/>
</div>
<br/>
<div id="divbuy" class="ClearBoth PadBottom">
  <span class="SectionHeader Block" >Buys</span>  
    <asp:UpdatePanel ID="upStatus" runat="server" UpdateMode="Conditional" >
      <Triggers >
        <asp:AsyncPostBackTrigger ControlID="btnFilter" EventName="Click"/>
      </Triggers>
      <ContentTemplate >
        <asp:HiddenField ID="hfSummaryVis" runat="server" />
        <asp:GridView ID="gvSummary" runat="server" AutoGenerateColumns="False" 
          CssClass="ContrastTable WideTable" GridLines="None" 
          onrowdatabound="gvSummary_RowDataBound">
          <EmptyDataTemplate>No Records Found</EmptyDataTemplate>
          <RowStyle CssClass="MainTableRow" />
          <AlternatingRowStyle CssClass="AlternateRow" />
          <HeaderStyle CssClass="HeaderRow" />
          <Columns>
            <asp:TemplateField>
              <ItemTemplate>
                <asp:LinkButton ID="lkBtnOpen" runat="server" CssClass="Expand ButtonCell PlainLink"  
                  ToolTip="Click to see details of the date's orders."
                  Text="   " OnClientClick="showCusipAccountDetails(" />
                <asp:LinkButton ID="lkBtnClose" runat="server" CssClass="Collapse ButtonCell PlainLink Hidden"
                  ToolTip="Click to close." 
                  Text="   " />
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Strategy Series">
              <ItemTemplate>
                <asp:Label ID="lblStrategySeries" runat="server" />
              </ItemTemplate>
            ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼泪也成诗 2024-12-20 15:07:44

您需要在页面上有一个脚本管理器,然后挂钩 //Do Something Here 的事件。

将其放入页面加载事件中:

if (typeof Sys !== "undefined") {
        if (typeof Sys.WebForms !== "undefined") {
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(function (sender, args) {
                //Do Something Here
            });
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, args) {
                //Do Something Here
            });
        }
    }

You need to have a script manager on the page and then hook into the events of //Do Something Here.

Put this in the page load event:

if (typeof Sys !== "undefined") {
        if (typeof Sys.WebForms !== "undefined") {
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(function (sender, args) {
                //Do Something Here
            });
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, args) {
                //Do Something Here
            });
        }
    }
遮云壑 2024-12-20 15:07:44

该隐藏文件是一个服务器控件,因此您必须获取该控件的 ClientID。试试这个

 alert('#<%= hfSummaryVis.ClientID %>').val();

希望这有帮助。

That Hidden filed is a server control so you have to get the ClientID of that control. Try this

 alert('#<%= hfSummaryVis.ClientID %>').val();

Hope this helps.

没有心的人 2024-12-20 15:07:44

我使用更新面板解决了这个问题。

I solved that using an update panel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文