更新面板问题

时间:2013-01-02 10:58:05

标签: c# asp.net updatepanel

Asalamu alikum家伙,我在同一页面上使用2个控件,两个控件都有自己的源代码中使用的更新面板,但问题是我在两个控件上都使用了pagging,当我到达一个页面的结束页面时控制,如果我尝试更改其他控件的页面索引,则第一个控件显示空白而没有记录。我在我的页面上使用特价控制和包控制。两个控件都使用数据集来显示记录

热门交易控件的热门代码:

URLMessage URLMessage = new URLMessage();
    PagedDataSource dsource = new PagedDataSource();
    DataSet _ds = new DataSet();
  public static  int pos;
    protected void Page_Load(object sender, EventArgs e)
    {
       if (!Page.IsPostBack)
        {
            this.ViewState["vs1"] = 0;    

        }
        pos=(int)this.ViewState["vs1"];

       fill(); 
    }
    private void fill()
    {
        RegistrationBAL rbl = new RegistrationBAL(0);
        rbl.LoadHotDeals(_ds);
        //******************Adding Regular Price to Dataset
        ////_ds.Tables[rbl.SqlEntityX].Columns.Add("RegPrice");
        ////foreach (DataRow item in _ds.Tables[rbl.SqlEntityX].Rows)
        ////{
        ////    item["RegPrice"] = (Convert.ToDouble(item["BaseRate"]) + 0.2 * Convert.ToDouble(item["BaseRate"]));

        ////}

        dsource.DataSource = _ds.Tables[rbl.SqlEntityX].DefaultView;
        dsource.PageSize = 2;
        dsource.AllowPaging = true;
        dsource.CurrentPageIndex = pos;
        btnfirst.Enabled = !dsource.IsFirstPage;
        btnprevious.Enabled = !dsource.IsFirstPage;
        btnlast.Enabled = !dsource.IsLastPage;
        btnnext.Enabled = !dsource.IsLastPage;
        dlHotDeals.DataSource = dsource;
        dlHotDeals.DataBind(); 
    }
    protected void btnfirst_Click(object sender, EventArgs e)
    {
        pos = 0;
        fill();
    }

    protected void btnprevious_Click(object sender, EventArgs e)
    {
        pos = (int)this.ViewState["vs1"];
        pos -= 1;
        this.ViewState["vs1"] = pos;
        fill();
    }

    protected void btnnext_Click(object sender, EventArgs e)
    {
        pos = (int)this.ViewState["vs1"];
        pos += 1;
        this.ViewState["vs1"] = pos;
        fill();
    }

    protected void btnlast_Click(object sender, EventArgs e)
    {
        pos = dsource.PageCount - 1;
        fill();
    }


    protected void dlHotDeals_ItemDataBound(object sender, DataListItemEventArgs e)
    {

        int rtid,rgid;
       // double BaseRate;
      //  BaseRate = WebHelper.Cast(((Label)e.Item.FindControl("lblPrice")).Text, 0);
      // Label lbl = (Label)e.Item.FindControl("lblRegPrice");
     // lbl.Text = (BaseRate + (0.2 * BaseRate)).ToString();
        HtmlAnchor lnkBookNow = (HtmlAnchor)e.Item.FindControl("lnkBook");

         rtid = WebHelper.Cast(((Label)e.Item.FindControl("lblRTID")).Text, 0);
        rgid=WebHelper.Cast(((Label)e.Item.FindControl("lblRegID")).Text, 0);
        lnkBookNow.HRef ="~/RoomTypeDetails.aspx?"+URLMessage.Encrypt( "RTID=" +rtid.ToString() + "&RegID=" + rgid.ToString());

    }
}

打包包控件的代码:

    PagedDataSource adsource = new PagedDataSource();
    DataSet _ds = new DataSet();
   public static int p;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            this.ViewState["vs"] = 0;    

        }
        p=(int)this.ViewState["vs"];
        fill();
    }
    private void fill()
    {
        PackageBAL pbl = new PackageBAL(0);
        pbl.LoadPackagesAll(_ds);

        adsource.DataSource = _ds.Tables[pbl.SqlEntityX].DefaultView;
        adsource.PageSize = 2;
        adsource.AllowPaging = true;
        adsource.CurrentPageIndex = p;
        btnfirst.Enabled = !adsource.IsFirstPage;
        btnprevious.Enabled = !adsource.IsFirstPage;
        btnlast.Enabled = !adsource.IsLastPage;
        btnnext.Enabled = !adsource.IsLastPage;
        dlPackage.DataSource = adsource;
        dlPackage.DataBind(); 
    }
    protected void btnfirst_Click(object sender, EventArgs e)
    {
        p = 0;
        fill();
    }

    protected void btnprevious_Click(object sender, EventArgs e)
    {
        p = (int)this.ViewState["vs"];
        p -= 1;
        this.ViewState["vs"] = p;
        fill();
    }

    protected void btnnext_Click(object sender, EventArgs e)
    {
        p = (int)this.ViewState["vs"];
        p += 1;
        this.ViewState["vs"] = p;
        fill();
    }

    protected void btnlast_Click(object sender, EventArgs e)
    {
        p = adsource.PageCount - 1;
        fill();
    }

显示控件的主页上的代码

<%@ Page Title="" Language="C#" MasterPageFile="~/main1.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Src="Registration/ShowPackagesControl.ascx" TagName="ShowPackagesControl"
    TagPrefix="uc2" %>
<%@ Register Src="Registration/SearchInputControl.ascx" TagName="SearchInputControl"
    TagPrefix="uc1" %>
<%@ Register Src="Registration/ShowHotDealsControl.ascx" TagName="ShowHotDealsControl"
    TagPrefix="uc3" %>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="Server">
    <link href="js/css/nivo-slider.css" rel="stylesheet" type="text/css" />
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css"
        rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

    <%--<script src="js/css/jquery.min.js" type="text/javascript"></script>--%>

    <script src="js/css/custom.js" type="text/javascript"></script>

    <script src="js/css/slides.min.jquery.js" type="text/javascript"></script>

    <script src="js/css/jquery.nivo.slider.js" type="text/javascript"></script>

    <script src="js/css/jquery.kwicks-1.5.1.pack.js" type="text/javascript"></script>

</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div class="mainwrap">
        <div class="leftsection">
            <uc1:SearchInputControl ID="SearchInputControl" runat="server" />
        </div>
        <div class="rightsection">
            <div class="slideshow">
                <div id="slides">
                    <div id="slider-big">
                        <div class="slides_container big-slider">
                            <!-- SLIDER STARTS-->
                            <!-- SLIDER CONTENT STARTS-->
                            <div class="slide">
                                <img src="js/images/slideshow/1.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/2.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/arab.png" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/4.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/5.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/6.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/7.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/8.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/9.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/10.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/11.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/12.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/13.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/14.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/15.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/16.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/17.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/18.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/19.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/20.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/21.jpg" alt=" " width="610" height="350" />
                            </div>
                            <div class="slide">
                                <img src="js/images/slideshow/22.jpg" alt=" " width="610" height="350" />
                            </div>
                        </div>
                        <!-- SLIDESHOW CONTAINER ENDS-->
                    </div>
                    <div class="slides-nav">
                        <a href="#" class="prev">Previous Slide</a> <a href="#" class="next">Next Slide</a>
                        <!--END .slides-nav -->
                    </div>
                </div>
            </div>
        </div>

    </div>

    <div class="contentsection">
        <div class="verbox">


            <%-- <div class="verbox_title">
                Hot Deals...
            </div>
            <div class="verbox_content">
            <img src="Images/Omakan-Hotel-14.jpg" />
                Located just off Regent Street, the prestigious Langham London has a chic and glamorous bar, Artesian, and a stylish new restaurant, Roux at the Landau.

            </div>
            <div class="verbox_content_bottom">
                <a href="#">Read more....</a>
            </div>
              <div class="verbox_title">
                Hot Deals...
            </div>
            <div class="verbox_content">
            <img src="Images/super8deal.jpg" />
                2 Adults for three days and three nights in the hotel residency in srinagar. This package also includes free breakfast and dinner for the couple.Also in this package you will get visits to two most famous places of kashmir that is pahagam and srinagar.  Residency is provided with high class facilites such as swimming pool,gym etc.     
            </div>
            <div class="verbox_content_bottom">
                <a href="#">Read more....</a>
            </div>
           --%>
            <uc3:ShowHotDealsControl ID="ShowHotDealsControl1" runat="server" />
        </div>
        <div class="verbox">
            <%-- <div class="verbox_title">
                Best Packages...
            </div>
            <div class="verbox_content">
                <img src="Images/Marriot_1590604c.jpg" />
              The Birmingham Britannia Hotel is opposite Birmingham New Street Station. It offers rooms with baths and showers, Jenny’s Restaurant, where you can see the chef’s at work, and Harvey’s Ba
            </div>
            <div class="verbox_content_bottom">
                <a href="#">Read more....</a>
            </div>--%>

            <uc2:ShowPackagesControl ID="ShowPackagesControl1" runat="server" />
        </div>
        <div class="verbox"> 
            <div class="latestverbox_title">
                <div class="iconupcommingevents">
                </div>
                Upcomming Events..<div class="pannelpaggingbuttons">
                    <%--<asp:Button ID="btnfirst" runat="server" CssClass="refresh" ToolTip="Refresh" OnClick="btnfirst_Click" />
                     <asp:Button ID="btnprevious" runat="server" CssClass="previous" ToolTip="Previous"
                         OnClick="btnprevious_Click" />
                     <asp:Button ID="btnnext" runat="server" CssClass="next" ToolTip="Next" OnClick="btnnext_Click" />--%></div>
            </div>
            <div class="latestverbox_content">
                <div class="propertyname">
                    Water Rafting in Phalgam...
                </div>
                <div class="propertyimage">
                    <img src="Images/raft_new3.jpg" />
                </div>
                <p style="margin-bottom: 0px; float: left; overflow: hidden; height: 60px; width: 160px;">
                    <span style="padding-left: 8px; padding-right: 8px; width: 150px; float: left; text-align: justify;">
                        The sport of white water river rafting calls for a triumph over the swift swirling
                        river as it gushes past spectacular mountains. It is practised mainly in the upper
                        reaches where the water is wild and white as it frothes and foams, crashing against
                        narrow gorges, rocky outcrops and falls at deep gradients. </span>
                </p>
                <div class="propertylocation">
                    <em>Location:&nbsp;<br />
                    </em>
                </div>
                <div style="float: right;">
                    <a href="#">Read more...</a>
                </div>
            </div>
            <div class="latestverbox_content">
                <div class="propertyname">
                    Skiing in Gulmarg...
                </div>
                <div class="propertyimage">
                    <img src="Images/images (4).jpg" />
                </div>
                <p style="margin-bottom: 0px; float: left; overflow: hidden; height: 60px; width: 160px;">
                    <span style="padding-left: 8px; padding-right: 8px; width: 150px; float: left; text-align: justify;">
                    Skiing in Gulmarg bring you joy, adventure and nature near you. Gulmarg is located
                    56-km south west of Srinagar, provides natural slopes, inclines, snow and gondola
                    is primarily country’s premier ski resort and a favorite winter tourist destination.
                    Gulmarg is also capital of winter game and having institute provide comprehensive
                    training of ski.</span>
                </p>
                <div class="propertylocation">
                    <em>Location:&nbsp;<br />
                    </em>
                </div>
                <div style="float: right;">
                    <a href="#">Read more...</a>
                </div>
            </div>
        </div>
    </div>

</asp:Content>

热门交易控制代码:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ShowHotDealsControl.ascx.cs"
    Inherits="Registration_ShowHotDealsControl" %>
     <asp:UpdatePanel ID="panel" runat="server">
     <ContentTemplate>
<div class="latestverbox_title">
    <div class="iconhotdeals">
    </div>
    Hot Deals..<div class="pannelpaggingbuttons">
        <asp:Button ID="btnfirst" runat="server" CssClass="refresh" ToolTip="Refresh" OnClick="btnfirst_Click" />
        <asp:Button ID="btnprevious" runat="server" CssClass="previous" ToolTip="Previous"
            OnClick="btnprevious_Click" />
        <asp:Button ID="btnnext" runat="server" CssClass="next" ToolTip="Next" OnClick="btnnext_Click" /></div>
</div>
<asp:DataList ID="dlHotDeals" runat="server" Width="112px" 
             onitemdatabound="dlHotDeals_ItemDataBound">
    <ItemTemplate>
        <div>
            <asp:Label ID="lblRegID" Visible="false" runat="server" Text='<%#Eval("RegID") %>'></asp:Label>
            <asp:Label ID="lblRTID" Visible="false" runat="server" Text='<%#Eval("RTID") %>'></asp:Label>
        </div>
        <div class="latestverbox_content">
            <div class="propertyname">
                <asp:Label ID="lblHotelName" runat="server" Text='<%#Eval("PropertyName") %>'></asp:Label></div>
            <div class="propertyimage">
                <img id="Img1" alt="" width="180px" height="102px" src='PropertyImages/1/<%#Eval("MainImage") %>' />
            </div>
            <div class="propertylocation">
                <em>Location:&nbsp;<br />
                </em>
                <asp:Label ID="lblAddress" runat="server" Text='<%#Eval("Address") %>'></asp:Label>,
                <asp:Label ID="Label1" runat="server" Text='<%#Eval("City") %>'></asp:Label>
            </div>
            <div class="propertyroomtype">
                <em>Room Type:&nbsp;</em><br />
                <asp:Label ID="lblRoomTypeName" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
            </div>
            <div class="propertyregularprice">
                <em>Regular Price: </em>
                <br />
                <amount><span class="WebRupee">Rs.&nbsp;</span><asp:Label ID="lblRegPrice" runat="server" Text='<%#string.Format("{0:0.00}",Eval("RegPrice")) %>'></asp:Label></amount>
            </div>
            <div class="propertyofferprice">
                <em>Offer Price: </em>
                <br />
                <span class="WebRupee">Rs.&nbsp;</span> <asp:Label ID="lblPrice" runat="server" Text='<%#string.Format("{0:0.00}",Eval("BaseRate")) %>'></asp:Label>
            </div>
            <div class="booknow"><a ID="lnkBook" href="" ToolTip="Book Now" width="67" runat="server">Book Now</a></div>
        </div>
    </ItemTemplate>
</asp:DataList>
<div class="latestverbox_content_bottom">
</div>

<%--pagging***************************--%>
<asp:Button ID="btnlast" runat="server" Font-Bold="true" Height="31px" Width="43px"
    OnClick="btnlast_Click" Visible="false" />
   </ContentTemplate></asp:UpdatePanel>

包控件上的代码

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ShowPackagesControl.ascx.cs"
    Inherits="Registration_ShowPackagesControl" %>
 <asp:UpdatePanel ID="panel1" runat="server"><ContentTemplate>
<div class="latestverbox_title">
    <div class="iconbestpackages">
    </div>
    Best Packages...
    <div class="pannelpaggingbuttons">
        <asp:Button ID="btnfirst" runat="server" CssClass="refresh" OnClick="btnfirst_Click" />
        <asp:Button ID="btnprevious" runat="server" CssClass="previous" OnClick="btnprevious_Click" />
        <asp:Button ID="btnnext" CssClass="next" runat="server" OnClick="btnnext_Click" />
    </div>
    <asp:Button ID="btnlast" runat="server" Font-Bold="true" Text=">>" Height="31px"
        Width="43px" OnClick="btnlast_Click" Visible="false" />
</div> 

<asp:DataList ID="dlPackage" runat="server">
    <ItemTemplate>
        <div class="latestverbox_content">
            <div class="propertyname">
                <asp:Label ID="lblTitle" runat="server" Text='<%#Eval("PackageTitle") %>'></asp:Label>
            </div>
            <div class="propertyimage">
                <img id="Img1" alt="" src='PropertyImages/1/<%#Eval("PackageImage") %>' />
                <p style="clear: both; margin-bottom: 0px; float: left; overflow: hidden; height: 40px;
                    width: 195px;">
                    <span style="padding-left: 8px; padding-right: 8px; width: 180px; float: left; text-align: justify;">
                        <asp:Label ID="lblDescription" runat="server" Text='<%#Eval("PackageDescription") %>'></asp:Label></span>
                </p>
            </div>
            <div class="propertylocation" style="width: 135px;">
                <em>Location:&nbsp;<br />
                    <asp:Label ID="lblCity" runat="server" Text='<%#Eval("City") %>'></asp:Label>
                </em>
            </div>
            <div class="propertyroomtype" style="width: 135px;">
                <em>Duration :&nbsp;</em><br />
                <asp:Label ID="Label2" runat="server" Text='<%#Eval("Duration")+" Day(s) and Night(s) " %>'></asp:Label> 
            </div>
           <div class="propertyregularprice" style="width: 135px;">


              <asp:Label ID="Label3" runat="server" Text='<%#"For " + Eval("NumberOfPeople")+" Adult(s)" %>'></asp:Label>
            </div>
            <div class="propertyofferprice" style="width: 135px;">
                <em>Offer Price: </em>
                <br />
                <span class="WebRupee">Rs.&nbsp;&nbsp;</span><asp:Label ID="Label4" runat="server"
                    Text='<%#string.Format("{0:0.00}",Eval("Price")) %>'></asp:Label>
            </div>
            <div style="clear: both; float: right; text-align: right;width:100px;">
                <asp:LinkButton ID="LinkButton1" Width="90" runat="server">Read More..</asp:LinkButton></div>
        </div>
    </ItemTemplate>
</asp:DataList>
</ContentTemplate></asp:UpdatePanel>
<%--***************Pagging code--%>

1 个答案:

答案 0 :(得分:1)

尝试使用UpdateMode="Conditional"ChildrenAsTriggers="true"作为更新面板, 并添加Triggers ,这会阻止一个更新面板影响其他面板

<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
  <Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnOk" EventName="Click" />
  </Triggers>
  <ContentTemplate>

  //Your contents here

  </ContentTemplate>
</asp:UpdatePanel>

Valekum Salaam。

相关问题