如何在加载选项卡内容时显示加载图像

how to show loading image when tab content is loading?

本文关键字:加载 显示 图像 选项      更新时间:2023-12-14

我有一个有三个面板的tabcontainer,里面有gridview。当我的用户点击选项卡时,网格视图被加载。我希望在加载网格视图之前,应该显示一个img gif,并且应该在网格完全加载后隐藏。为此,我将代码写成:

<%@ Page Language="C#" AutoEventWireup="true"  CodeBehind="example.aspx.cs"
    Inherits="example" %>
<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <script type="text/javascript">
        $(function() {

        $("#mytab").mytab({
                ajaxOptions: {
                    type: 'POST',
                    data: postData,
                    beforeSend: function() {
                        $('#loader').show();
                    },
                    complete: function() {
                        $("#loader").hide();
                    }
                }
            });
        });
</script>

</head>
<body>
    <form id="form2" runat="server">
    <iframe id="iFrame2" runat="server" height="2px" width="2px"></iframe>
        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
    <div>
        <asp:ScriptManager ID="ScriptManager2" runat="server" EnablePartialRendering="true">
        </asp:ScriptManager>

    </div>
  <asp:Panel ID="loader" runat="server" Wrap="true" CssClass="body"  >
                    <table cellpadding="5" cellspacing="5" style="width:322px; height:245px; border:1">
                        <tr>
                            <td style="width:322px; height:245px; border:1">
                                <asp:Image ID="Image1" Width="322px" Height="245px" BorderWidth="0" runat="server" ImageUrl="Images/loading.gif" />
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
       <cc1:TabContainer ID="mytab" runat="server"  Width="100%"
                                Visible="true" AutoPostBack="true" >
                                <cc1:TabPanel runat="server"   HeaderText="application" ID="TabPanel1" 
                                    >
                                    <ContentTemplate>
                                    <asp:Panel ID="Panel1" runat="server">
                                        <table class="outline-tabs">
                                            <tr class="pagination-row">
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                                        <ContentTemplate>
                                                            <asp:GridView ID="GridView1" runat="server" CssClass="tblGrid" AllowSorting="True">
                                                    </asp:GridView>
                                                        </ContentTemplate>
                                                    </asp:UpdatePanel>
                                                </td>
                                            </tr>
                                        </table>
                                    </asp:Panel>
                                    </ContentTemplate>
                                </cc1:TabPanel>

            </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>

但当我运行应用程序时,我会得到一个错误:

Microsoft JScript runtime error: Object expected

上面的代码有什么问题,因为我使用的是jquery,所以缺少任何文件。

试试这个,而不是你的。。。

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script>
$(document).ready(function() {
$("#mytab").mytab({
                ajaxOptions: {
                    type: 'POST',
                    data: postData,
                    beforeSend: function() {
                        $('#loader').show();
                    },
                    success: function(data) {
                      console.dir(data)
                    },
                    error: function(error) {
                      console.dir('ERROR: ' + error)
                    }
                    complete: function() {
                        $("#loader").hide();
                    }
                }
            });
})
    </script>

使用console.dir();您可以在chrome或firebug中跟踪传入的数据对象。ie不是一个适合开发的浏览器。

希望这能有所帮助。

啊,我明白了。示例代码使用tabs而不是mytab。这意味着示例代码使用jquery ui(您可以在这里找到它:http://jqueryui.com/)。

对于选项卡,您可以在此处找到文档(http://jqueryui.com/demos/tabs/klick上的链接"查看源代码")。

因此,请查看您使用firebug或webinspector编译的源代码,并查找jquery、jquery ui以及jquery ui的所有源文件,如图像和css。如果没有实现->获取源。

在此之后,您应该能够运行您的代码。

有关更多帮助,请发布您的编译的(!)源代码。