>逐个加载并显示

在这里我把我的示例代码。 请纠正错误。 在示例代码中,我想逐个加载UpdatePanelBodySub1,UpdatePanelBodySub2,UpdatePanelBodySub3和UpdatePanelBodySub4。 如果一个updatepanel立即加载所有记录并立即显示,那么下一个updatepanel将开始工作...。 请帮帮我。 (Visual Studio 2008和Framework 3.5)

Default.aspx的

主页 - 多个UpdatePanel

        <UsrCtrl:MainControl ID="mainControl1" runat="server" EnableViewState="true" />
    </div>
</form>

使用System的Default.aspx.cs; 使用System.Web.UI; 使用System.Web.UI.WebControls;

public partial class _Default:Page {/// /// /// /// protected override void OnPreRenderComplete(EventArgs e){TextBox txtIsSearch =(TextBox)mainControl1.FindControl(“headerControl1”)。FindControl(“txtIsSearch”);

    if (Convert.ToBoolean(txtIsSearch.Text))
    {
        UpdatePanel updatePanelBodySub;

        updatePanelBodySub =
            (UpdatePanel)
            mainControl1.FindControl("bodyControl1").FindControl("bodySubControl1").FindControl(
                "UpdatePanelBodySub1");
        updatePanelBodySub.DataBind();

        updatePanelBodySub =
            (UpdatePanel)
            mainControl1.FindControl("bodyControl1").FindControl("bodySubControl2").FindControl(
                "UpdatePanelBodySub2");
        updatePanelBodySub.DataBind();

        updatePanelBodySub =
            (UpdatePanel)
            mainControl1.FindControl("bodyControl1").FindControl("bodySubControl3").FindControl(
                "UpdatePanelBodySub3");
        updatePanelBodySub.DataBind();

        updatePanelBodySub =
            (UpdatePanel)
            mainControl1.FindControl("bodyControl1").FindControl("bodySubControl4").FindControl(
                "UpdatePanelBodySub4");
        updatePanelBodySub.DataBind();

        txtIsSearch.Text = "false";
    }

    base.OnPreRenderComplete(e);
}

}

MainControl.ascx

    <asp:UpdateProgress ID="UpdateProgressMain" runat="server" AssociatedUpdatePanelID="UpdatePanelMain" DisplayAfter="50">
        <ProgressTemplate>
            <img src="loading.gif" alt="Loading ... " title="Loading ... " />
        </ProgressTemplate>
    </asp:UpdateProgress>

    <h1>Search data from 4 different databases</h1>

    <UsrCtrl:HeaderControl ID="headerControl1" runat="server" EnableViewState="true" />

    <UsrCtrl:BodyControl ID="bodyControl1" runat="server" EnableViewState="true" />

</ContentTemplate>

MainControl.ascx.cs

使用系统;

public partial class MainControl:System.Web.UI.UserControl {protected void Page_Load(object sender,EventArgs e){

}

}

HeaderControl.ascx

搜索条件



HeaderControl.ascx.cs

使用系统; 使用System.Web.UI.WebControls;

public partial class HeaderControl:System.Web.UI.UserControl {protected void Page_Load(object sender,EventArgs e){

}
protected void btnSearch_Click(object sender, EventArgs e)
{
    TextBox txtPageNumber;

    txtPageNumber =
        (TextBox)
        this.Parent.Parent.Parent.FindControl("bodyControl1").FindControl("bodySubControl1").FindControl(
            "txtPageNumber");
    // this                         --> ASP.hedercontrol_ascx
    // this.Parent                  --> System.Web.UI.Control
    // this.Parent.Parent           --> System.Web.UI.UpdatePanel
    // this.Parent.Parent.Parent    --> ASP.maincontrol_ascx

    txtPageNumber.Text = "1";

    txtPageNumber =
        (TextBox)
        this.Parent.Parent.Parent.FindControl("bodyControl1").FindControl("bodySubControl2").FindControl(
            "txtPageNumber");
    txtPageNumber.Text = "1";

    txtPageNumber =
        (TextBox)
        this.Parent.Parent.Parent.FindControl("bodyControl1").FindControl("bodySubControl3").FindControl(
            "txtPageNumber");
    txtPageNumber.Text = "1";

    txtPageNumber =
        (TextBox)
        this.Parent.Parent.Parent.FindControl("bodyControl1").FindControl("bodySubControl4").FindControl(
            "txtPageNumber");
    txtPageNumber.Text = "1";

    txtIsSearch.Text = "true";
}

}

BodyControl.ascx

搜索结果







BodyControl.ascx.cs

使用系统;

公共部分类BodyControl:System.Web.UI.UserControl {protected void Page_Load(object sender,EventArgs e){

}

}

BodySubControl1.ascx

    <asp:UpdateProgress ID="UpdateProgressBodySub1" runat="server" AssociatedUpdatePanelID="UpdatePanelBodySub1" DisplayAfter="50">
        <ProgressTemplate>
            <img src="loading.gif" alt="Loading ... " title="Loading ... " />
        </ProgressTemplate>
    </asp:UpdateProgress>

    <h3>From database 1</h3>

    <asp:GridView ID="GridViewBodySub1" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField HeaderText="Search Answer" DataField="SearchAns" />
        </Columns>
    </asp:GridView>

    <asp:LinkButton ID="lnkPrevious" runat="server" Text="Previous" 
        ForeColor="Blue" onclick="lnkPrevious_Click"></asp:LinkButton>
    <asp:LinkButton ID="lnkNext" runat="server" Text="Next" ForeColor="Blue" 
        onclick="lnkNext_Click"></asp:LinkButton>
    <asp:TextBox ID="txtPageNumber" runat="server" Text="1" Visible="false"></asp:TextBox>

</ContentTemplate>

BodySubControl1.ascx.cs

使用系统; 使用System.Collections.Generic; 使用System.Web.UI; 使用System.Web.UI.WebControls;

公共部分类BodySubControl1:UserControl {保护无效UpdatePanel_DataBinding(对象发件人,EventArgs e){GridViewBodySub1.DataSource = GetRecords(); GridViewBodySub1.DataBind(); }

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lnkPrevious_Click(object sender, EventArgs e)
{
    int pageNumber = Convert.ToInt32(txtPageNumber.Text);

    if (pageNumber > 1)
    {
        pageNumber -= 1;
    }

    txtPageNumber.Text = Convert.ToString(pageNumber);

    UpdatePanelBodySub1.DataBind();
}

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lnkNext_Click(object sender, EventArgs e)
{
    int pageNumber = Convert.ToInt32(txtPageNumber.Text);

    pageNumber += 1;

    txtPageNumber.Text = Convert.ToString(pageNumber);

    UpdatePanelBodySub1.DataBind();
}

/// <summary>
/// In actual case this function fetching record from database
/// For testing purpose I wrote like this.
/// </summary>
/// <returns></returns>
private List<SearchResult> GetRecords()
{
    List<SearchResult> strList = new List<SearchResult>();

    TextBox txtSearchCriteria =
        (TextBox) this.Parent.Parent.Parent.Parent.FindControl("headerControl1").FindControl("txtSearchCriteria");

    // this                                 --> ASP.bodysubcontrol1_ascx
    // this.Parent                          --> ASP.bodycontrol_ascx
    // this.Parent.Parent                   --> System.Web.UI.Control
    // this.Parent.Parent.Parent            --> System.Web.UI.UpdatePanel
    // this.Parent.Parent.Parent.Parent     --> ASP.maincontrol_ascx



    int recordNumberStart = ((Convert.ToInt32(txtPageNumber.Text) - 1) * 10) + 1;
    int recordNumberEnd = recordNumberStart + 9;

    for (int i = recordNumberStart; i <= recordNumberEnd; i++)
    {
        strList.Add(new SearchResult(string.Concat("DB1 :", txtSearchCriteria.Text.Trim(), " ", i.ToString())));
    }

    for (long i = 0; i < 999999999; i++)
    {
        // real case it will not come
    }

    return strList;
}

}

BodySubControl2.ascx

    <asp:UpdateProgress ID="UpdateProgressBodySub2" runat="server" AssociatedUpdatePanelID="UpdatePanelBodySub2" DisplayAfter="50">
        <ProgressTemplate>
            <img src="loading.gif" alt="Loading ... " title="Loading ... " />
        </ProgressTemplate>
    </asp:UpdateProgress>

    <h3>From database 2</h3>

    <asp:GridView ID="GridViewBodySub2" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField HeaderText="Search Answer" DataField="SearchAns" />
        </Columns>
    </asp:GridView>

    <asp:LinkButton ID="lnkPrevious" runat="server" Text="Previous" 
        ForeColor="Blue" onclick="lnkPrevious_Click"></asp:LinkButton>
    <asp:LinkButton ID="lnkNext" runat="server" Text="Next" ForeColor="Blue" 
        onclick="lnkNext_Click"></asp:LinkButton>
    <asp:TextBox ID="txtPageNumber" runat="server" Text="1" Visible="false"></asp:TextBox>

</ContentTemplate>

BodySubControl2.ascx.cs

使用系统; 使用System.Collections.Generic; 使用System.Web.UI; 使用System.Web.UI.WebControls;

公共部分类BodySubControl2:UserControl {保护无效UpdatePanel_DataBinding(对象发件人,EventArgs e){GridViewBodySub2.DataSource = GetRecords(); GridViewBodySub2.DataBind(); }

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lnkPrevious_Click(object sender, EventArgs e)
{
    int pageNumber = Convert.ToInt32(txtPageNumber.Text);

    if (pageNumber > 1)
    {
        pageNumber -= 1;
    }

    txtPageNumber.Text = Convert.ToString(pageNumber);

    UpdatePanelBodySub2.DataBind();
}

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lnkNext_Click(object sender, EventArgs e)
{
    int pageNumber = Convert.ToInt32(txtPageNumber.Text);

    pageNumber += 1;

    txtPageNumber.Text = Convert.ToString(pageNumber);

    UpdatePanelBodySub2.DataBind();
}

/// <summary>
/// In actual case this function fetching record from database
/// For testing purpose I wrote like this.
/// </summary>
/// <returns></returns>
private List<SearchResult> GetRecords()
{
    List<SearchResult> strList = new List<SearchResult>();

    TextBox txtSearchCriteria =
        (TextBox)this.Parent.Parent.Parent.Parent.FindControl("headerControl1").FindControl("txtSearchCriteria");

    // this                                 --> ASP.bodysubcontrol2_ascx
    // this.Parent                          --> ASP.bodycontrol_ascx
    // this.Parent.Parent                   --> System.Web.UI.Control
    // this.Parent.Parent.Parent            --> System.Web.UI.UpdatePanel
    // this.Parent.Parent.Parent.Parent     --> ASP.maincontrol_ascx



    int recordNumberStart = ((Convert.ToInt32(txtPageNumber.Text) - 1) * 10) + 1;
    int recordNumberEnd = recordNumberStart + 9;

    for (int i = recordNumberStart; i <= recordNumberEnd; i++)
    {
        strList.Add(new SearchResult(string.Concat("DB2 :", txtSearchCriteria.Text.Trim(), " ", i.ToString())));
    }

    for (long i = 0; i < 999999999; i++)
    {
        // real case it will not come
    }

    return strList;
}

}

BodySubControl3.ascx

    <asp:UpdateProgress ID="UpdateProgressBodySub3" runat="server" AssociatedUpdatePanelID="UpdatePanelBodySub3" DisplayAfter="50">
        <ProgressTemplate>
            <img src="loading.gif" alt="Loading ... " title="Loading ... " />
        </ProgressTemplate>
    </asp:UpdateProgress>

    <h3>From database 3</h3>

    <asp:GridView ID="GridViewBodySub3" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField HeaderText="Search Answer" DataField="SearchAns" />
        </Columns>
    </asp:GridView>

    <asp:LinkButton ID="lnkPrevious" runat="server" Text="Previous" 
        ForeColor="Blue" onclick="lnkPrevious_Click"></asp:LinkButton>
    <asp:LinkButton ID="lnkNext" runat="server" Text="Next" ForeColor="Blue" 
        onclick="lnkNext_Click"></asp:LinkButton>
    <asp:TextBox ID="txtPageNumber" runat="server" Text="1" Visible="false"></asp:TextBox>

</ContentTemplate>

BodySubControl3.ascx.cs

使用系统; 使用System.Collections.Generic; 使用System.Web.UI; 使用System.Web.UI.WebControls;

公共部分类BodySubControl3:UserControl {保护无效UpdatePanel_DataBinding(对象发件人,EventArgs e){GridViewBodySub3.DataSource = GetRecords(); GridViewBodySub3.DataBind(); }

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lnkPrevious_Click(object sender, EventArgs e)
{
    int pageNumber = Convert.ToInt32(txtPageNumber.Text);

    if (pageNumber > 1)
    {
        pageNumber -= 1;
    }

    txtPageNumber.Text = Convert.ToString(pageNumber);

    UpdatePanelBodySub3.DataBind();
}

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lnkNext_Click(object sender, EventArgs e)
{
    int pageNumber = Convert.ToInt32(txtPageNumber.Text);

    pageNumber += 1;

    txtPageNumber.Text = Convert.ToString(pageNumber);

    UpdatePanelBodySub3.DataBind();
}

/// <summary>
/// In actual case this function fetching record from database
/// For testing purpose I wrote like this.
/// </summary>
/// <returns></returns>
private List<SearchResult> GetRecords()
{
    List<SearchResult> strList = new List<SearchResult>();

    TextBox txtSearchCriteria =
        (TextBox)this.Parent.Parent.Parent.Parent.FindControl("headerControl1").FindControl("txtSearchCriteria");

    // this                                 --> ASP.bodysubcontrol3_ascx
    // this.Parent                          --> ASP.bodycontrol_ascx
    // this.Parent.Parent                   --> System.Web.UI.Control
    // this.Parent.Parent.Parent            --> System.Web.UI.UpdatePanel
    // this.Parent.Parent.Parent.Parent     --> ASP.maincontrol_ascx



    int recordNumberStart = ((Convert.ToInt32(txtPageNumber.Text) - 1) * 10) + 1;
    int recordNumberEnd = recordNumberStart + 9;

    for (int i = recordNumberStart; i <= recordNumberEnd; i++)
    {
        strList.Add(new SearchResult(string.Concat("DB3 :", txtSearchCriteria.Text.Trim(), " ", i.ToString())));
    }

    for (long i = 0; i < 999999999; i++)
    {
        // real case it will not come
    }

    return strList;
}

}

BodySubControl4.ascx

    <asp:UpdateProgress ID="UpdateProgressBodySub4" runat="server" AssociatedUpdatePanelID="UpdatePanelBodySub4" DisplayAfter="50">
        <ProgressTemplate>
            <img src="loading.gif" alt="Loading ... " title="Loading ... " />
        </ProgressTemplate>
    </asp:UpdateProgress>

    <h3>From database 4</h3>

    <asp:GridView ID="GridViewBodySub4" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField HeaderText="Search Answer" DataField="SearchAns" />
        </Columns>
    </asp:GridView>

    <asp:LinkButton ID="lnkPrevious" runat="server" Text="Previous" 
        ForeColor="Blue" onclick="lnkPrevious_Click"></asp:LinkButton>
    <asp:LinkButton ID="lnkNext" runat="server" Text="Next" ForeColor="Blue" 
        onclick="lnkNext_Click"></asp:LinkButton>
    <asp:TextBox ID="txtPageNumber" runat="server" Text="1" Visible="false"></asp:TextBox>

</ContentTemplate>

BodySubControl4.ascx.cs

使用系统; 使用System.Collections.Generic; 使用System.Web.UI; 使用System.Web.UI.WebControls;

公共部分类BodySubControl4:UserControl {保护无效UpdatePanel_DataBinding(对象发件人,EventArgs e){GridViewBodySub4.DataSource = GetRecords(); GridViewBodySub4.DataBind(); }

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lnkPrevious_Click(object sender, EventArgs e)
{
    int pageNumber = Convert.ToInt32(txtPageNumber.Text);

    if (pageNumber > 1)
    {
        pageNumber -= 1;
    }

    txtPageNumber.Text = Convert.ToString(pageNumber);

    UpdatePanelBodySub4.DataBind();
}

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lnkNext_Click(object sender, EventArgs e)
{
    int pageNumber = Convert.ToInt32(txtPageNumber.Text);

    pageNumber += 1;

    txtPageNumber.Text = Convert.ToString(pageNumber);

    UpdatePanelBodySub4.DataBind();
}

/// <summary>
/// In actual case this function fetching record from database
/// For testing purpose I wrote like this.
/// </summary>
/// <returns></returns>
private List<SearchResult> GetRecords()
{
    List<SearchResult> strList = new List<SearchResult>();

    TextBox txtSearchCriteria =
        (TextBox)this.Parent.Parent.Parent.Parent.FindControl("headerControl1").FindControl("txtSearchCriteria");

    // this                                 --> ASP.bodysubcontrol4_ascx
    // this.Parent                          --> ASP.bodycontrol_ascx
    // this.Parent.Parent                   --> System.Web.UI.Control
    // this.Parent.Parent.Parent            --> System.Web.UI.UpdatePanel
    // this.Parent.Parent.Parent.Parent     --> ASP.maincontrol_ascx



    int recordNumberStart = ((Convert.ToInt32(txtPageNumber.Text) - 1) * 10) + 1;
    int recordNumberEnd = recordNumberStart + 9;

    for (int i = recordNumberStart; i <= recordNumberEnd; i++)
    {
        strList.Add(new SearchResult(string.Concat("DB4 :", txtSearchCriteria.Text.Trim(), " ", i.ToString())));
    }

    for (long i = 0; i < 999999999; i++)
    {
        // real case it will not come
    }

    return strList;
}

}

SearchResult.cs

/// /// SearchResult的摘要描述/// public class SearchResult {/// ///私有变量///私有字符串_SearchAns;

/// <summary>
/// Property
/// </summary>
public string SearchAns
{
    get
    {
        return _SearchAns;
    }
    set
    {
        _SearchAns = value;
    }
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="CurrentSeachAns"></param>
public SearchResult(string CurrentSeachAns)
{
    _SearchAns = CurrentSeachAns;
}

}

web.config中

Visual Studio中的Asp.Net配置选项。 通常位于 Windows Microsoft.Net Framework v2.x Config - >的machine.config.comments中可以找到完整的设置和注释列表,可以配置ASP.NET使用的安全身份验证模式识别传入的用户。 - >部分可以配置在执行请求期间发生未处理的错误时如何处理。 具体而言,它使开发人员能够配置html错误页面以显示错误堆栈跟踪。

    <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
        <error statusCode="403" redirect="NoAccess.htm" />
        <error statusCode="404" redirect="FileNotFound.htm" />
    </customErrors>
    -->
    <pages>
        <controls>
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </controls>
    </pages>
    <httpHandlers>
        <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    </httpHandlers>
    <httpModules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </httpModules>
</system.web>
<system.codedom>
    <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <providerOption name="CompilerVersion" value="v3.5"/>
            <providerOption name="WarnAsError" value="false"/>
        </compiler>
        <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <providerOption name="CompilerVersion" value="v3.5"/>
            <providerOption name="OptionInfer" value="true"/>
            <providerOption name="WarnAsError" value="false"/>
        </compiler>
    </compile

这是否必须是更新面板? 如果是我,我会使用jQuery和(理想情况下)MVC; 那么它非常简单,如下所示:

$('#div1').load(url1, function() {
    $('#div2').load(url2, function() {
        $('#div3').load(url3, function() {
            $('#div4').load(url4);
        });
    });
});

即我们使用每个回调来启动下一个div加载,但将每个div视为无关的请求。

链接地址: http://www.djcxy.com/p/43789.html

上一篇: > loading and displaying one by one

下一篇: ASP.net Custom Http Modules