0

我有一个Asp.Net Gridview绑定到DataSet代码隐藏文件中的 a 。此 gridview 绑定发生在单击页面按钮时。但是在单击该按钮时,整个页面都会刷新......并且我在该页面上有预先存在的 Asp.Net 图表,由于页面刷新而消失。

现在,我可以使用更新面板来避免这种情况。但按钮和网格应该在更新面板的同一个 Div 中。对我来说,按钮位于页面的其他位置……而网格位于底部的某个位置。

无论如何只重新加载网格而不干扰页面中的其他元素..现在请不要用updatePanel回答,因为我已经使用它并且你知道问题所在。如果您有更好的解决方案或使用AJAX.

非常感谢,

马尼什

4

2 回答 2

1

现在,我可以使用更新面板来避免这种情况。但按钮和网格应该在更新面板的同一个 Div 中。对我来说,按钮在页面的其他地方......而网格在底部的某个地方

只需为更新面板使用触发器

 </asp:UpdatePanel>
 ....
     <Triggers>
         <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
     </Triggers>
 </asp:UpdatePanel>
于 2011-07-24T21:17:50.373 回答
1

Now, I can avoid this using a update panel.. but the button and grid should be in the same Div of update panel. For me, the button is somewhere else in the page... and the grid is somewhere in the bottom.

Not a problem!

<script type="text/javascript">
    function click(id) {
        var btn = document.getElementById(id);
        btn.click();
    }
</script>

<asp:Button id="btnToClick" runat="server" Text="Click me!" 
   OnClientClick="javascript:click('<%=btnThatLoads.ClientId %>');return false" />

<asp:UpdatePanel id="upnl" runat="server">
    <ContentTemplate>
        //Your grid goes here

        <asp:Button id="btnThatLoads" runat="server" 
          onclick="loadGrid" style="display: hidden;" />
    </ContentTemplate>
</asp:UpdatePanel>

And there you have it - a button in one part of the page triggering an async-postback in an Update Panel in a different part of the page.

于 2011-07-24T14:53:09.917 回答