简体   繁体   English

按需加载Ajax选项卡

[英]Load Ajax tabs on demand

I have three tabs. 我有三个标签。 I want load then on demand except first tab. 我要加载,然后按需加载,但第一个选项卡除外。 If i click the 2nd tab it will load the second tab. 如果我单击第二个选项卡,它将加载第二个选项卡。 My problem is If i load 2nd tab and go to 3rd tab and when i come back to the 2nd tab it is loading again. 我的问题是,如果我加载第二个选项卡并转到第三个选项卡,当我回到第二个选项卡时,它将再次加载。 That should not happen. 那不应该发生。 once the tab is loaded it should not load again. 一旦加载了标签页,就不会再次加载。 How to achieve this? 如何实现呢? here is my sample code.... 这是我的示例代码。

<cc1:TabContainer ID="tabEditTskContainer" OnActiveTabChanged="tabEditTskContainer_TabChanged"
OnClientActiveTabChanged="tabChanged" AutoPostBack="true" runat="server" Height="300px"
Width="100%" ActiveTabIndex="0">
<cc1:TabPanel runat="server" ID="tabEditTskPnl" Enabled="true" HeaderText="Current Balance History"
    Width="99%">
    <HeaderTemplate>
        Edit Task
    </HeaderTemplate>
    <ContentTemplate>
        <br />
    </ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="tabAttach" runat="server" Height="100%" Enabled="true" Width="99%">
    <HeaderTemplate>
        Attachments
    </HeaderTemplate>
    <ContentTemplate>
    </ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="tabAddNotes" Height="100%" runat="server" Enabled="true" Width="99%">
    <HeaderTemplate>
        Notes
    </HeaderTemplate>
    <ContentTemplate>
    </ContentTemplate>
</cc1:TabPanel>

<input type="hidden" runat="server" id="hdnTabAttach" />
        <input type="hidden" runat="server" id="hdntabAddNotes" />


function tabChanged(sender, args) {
        var tabIndex = sender.get_activeTabIndex();
        if (tabIndex == "1") {
            if (document.getElementById('hdnTabAttach').value == "0") {
                return true;
            }
            else
                return false;
        }
    }


protected void tabEditTskContainer_TabChanged(object sender, EventArgs e)
{
    try
    {
        int intTabIndex = tabEditTskContainer.ActiveTabIndex;

        if (intTabIndex == 1 && hdnTabAttach.Value != "1")
        {
            hdnTabAttach.Value = "1";
        }

        if (intTabIndex == 2)
        {

            DBLayer obj = new DBLayer();
            SqlCommand cmd = new SqlCommand();
            SqlParameter param = new SqlParameter("@fOrderID", SqlDbType.NVarChar, 255);
            param.Value = Session["selorderID"].ToString();
            param.Direction = ParameterDirection.Input;
            cmd.Parameters.Add(param);
            param = new SqlParameter("@fncatid", SqlDbType.NVarChar, 25);
            param.Value = "1";
            param.Direction = ParameterDirection.Input;
            cmd.Parameters.Add(param);
            DataSet dsGetNotes = obj.ExecuteDatasetSql("[usp_GetNotes]", cmd);
            Session["GvNotes"] = dsGetNotes;
            gvNotes.DataSource = dsGetNotes;
            gvNotes.DataBind();

        }

    }
    catch (Exception ex)
    {

    }

}

Quick and easy -- add a hidden form field to your aspx page and append on the tab name to its value. 快速简便-将隐藏的表单字段添加到aspx页面,然后在选项卡名称上附加其值。 Then, before you actually load a tab, make sure that value isn't included in the hidden form fields value. 然后,在实际加载选项卡之前,请确保该值未包含在隐藏的表单字段值中。

I believe this should work, but the problem is that you are using the built-in ajax stuff from .Net, which I find difficult to work around. 我相信这应该可以工作,但是问题是您正在使用.Net内置的ajax东西,我发现这很难解决。 Normally, client-side, I'd make a global variable that tells me what tabs have been loaded, and only load a tab if it hadn't been done before, otherwise, I'd just show the already loaded tab. 通常,在客户端,我将创建一个全局变量来告诉我已加载了哪些标签,并且仅在之前未完成加载时才加载标签,否则,我将仅显示已加载的标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM