页面加载多次 [英] Page Load Multiple Times

查看:92
本文介绍了页面加载多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建的应用程序出现异常问题,所以我要做的是用户可以查看预览他们创建了他们的广告,点击广告,这是一个动态链接,并被带到
新页面,将更详细地显示广告。然后运行更多详细信息页面以检查查询字符串,将查询sting的参数传递给从数据库中提取正确详细信息的方法。这部分工作正常,但是当返回
对象时,页面再次加载,调用相同的方法3次,但是使用null参数返回对不存在的对象的空引用。 

我试图重构代码,所以当页面加载时,除非搜索参数有效,否则不会从数据库中检索。当页面加载时,组件将无法工作,例如Image Carousel。 

I've tried to refactor the code so when a page loads it won't retrieve form the database unless the search parameters are valid. When the page loads, components won't work then, for example the Image Carousel. 

我已经尝试将参数硬编码到方法中,将完美地工作。只会加载一次。 

I've tried hard coding the parameters into the method, will work perfectly. will only load once. 

我创建了两个新页面,这些页面不会从母版页继承并使用完全相同的方法。工作得很好。我在两个不同的页面上尝试了这个方法,这些页面是从母版页继承的,同样的问题。 

I've created two new pages which do not inherit form a master page and used the exact same methods. works perfectly. I tried the method on a two different pages that are inherited form the master page and same problem. 

DetailedPage.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DataModels;


namespace Lenders.ie
{
    public partial class DetailAdvert : System.Web.UI.Page
    {
        public Advert_User ReturnedUserAdvet = new Advert_User();
        public BalAdvertManger BALMan = new BalAdvertManger();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            //Response.Cache.SetCacheability(HttpCacheability.NoCache);
            //Response.ExpiresAbsolute = DateTime.Now.AddMonths(-1);
            
            //GetData();
            //PopulatePage();

            //int UserID = Convert.ToInt32(Request.QueryString["UiD"]);
            //int AdvertID = Convert.ToInt32(Request.QueryString["AdID"]);

            if (!Page.IsPostBack)
            {
                GetData();          
            }

            

        }

        public void GetData()
        {
            //int UserID = 41;
            //int AdvertID = 2;

            int UserID = Convert.ToInt16(Request.QueryString["UiD"]);
            int AdvertID = Convert.ToInt16(Request.QueryString["AdID"]);
                        
            if (UserID != 0 || AdvertID != 0)
            {
                ReturnedUserAdvet = BALMan.ReturnDetailedAdvert(UserID, AdvertID);
                PopulatePage();
            }
            
            //int UserID = Convert.ToInt32(Request.QueryString["UiD"]);
            //int AdvertID = Convert.ToInt32(Request.QueryString["AdID"]);

            //int UserID = 41;
            //int AdvertID = 2;

            //ReturnedUserAdvet = BALMan.ReturnDetailedAdvert(UserID,AdvertID);
            

        }

        public void PopulatePage()
        {

        }

      
    }
}

Detailedpage.aspx

<%@ Page Title=""  Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeFile="DetailAdvert.aspx.cs" Inherits="Lenders.ie.DetailAdvert" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="col-lg-9">
    <div class="container">
        <div class="row">


            <!--Advert Image -->
            <div class="container">
                <div class="row">



                    <!-- Carosel goes here -->
                    <div class="row carousel-holder">         

		               <div class="col-xs-12 col-sm-12 col-md-12 col-lg-10">
                                <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
                                    <ol class="carousel-indicators">
                                        <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
                                        <li data-target="#carousel-example-generic" data-slide-to="1"></li>
                                        <li data-target="#carousel-example-generic" data-slide-to="2"></li>
                                    </ol>
                                    <div class="carousel-inner">
                                        <div class="item active">
                                            <img class="slide-image" id="Img1" runat="server" src="http://placehold.it/800x380" alt=""/>
                                        </div>
                                        <div class="item">
                                            <img class="slide-image" id="Img2" runat="server" src="http://placehold.it/800x380" alt=""/>
                                        </div>
                                        <div class="item">
                                            <img class="slide-image" id="Img3" runat="server" src="http://placehold.it/800x380" alt=""/>
                                        </div>
                                    </div>
                                    <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
                                        <span class="glyphicon glyphicon-chevron-left"></span>
                                    </a>
                                    <a class="right carousel-control"  href="#carousel-example-generic" data-slide="next">
                                        <span class="glyphicon glyphicon-chevron-right"></span>
                                    </a>
                                </div>
                            </div>

                    </div>
                </div>
            </div>

            <!--User Details-->
            <br />

            <div class="container">

                <div class="row">

                    <!-- Descriptin and profile view -->


                                    <div class="col-xs-12 col-sm-6 col-md-6 col-lg-5">
                                <div class="well well-sm">
                                    <div class="row">

                                                 

                                        <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                            <img src="" runat="server" id="imgProfilePic" alt="" class="img-rounded img-responsive" />
                                        </div>
                                        <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
                                            <h4>
                                                    
                                            <asp:Label ID="lblFristName" runat="server" Text=""></asp:Label>
                                            <asp:Label ID="lblSecondName" runat="server" Text=""></asp:Label>

                                            </h4>

                                            <small><cite title="Location"><asp:Label ID="lblLocation" runat="server" Text=""></asp:Label> <i class="glyphicon glyphicon-map-marker">
                                            </i></cite></small>
                                            <p>
                                                <i title="Email" class="glyphicon glyphicon-envelope"></i> <asp:Label ID="lblEmail" runat="server" Text=""></asp:Label>
                                                <br />
                                      
                                                <i title="Join Date" class="glyphicon glyphicon-user"></i> <asp:Label ID="lblJoinDate" runat="server" Text=""></asp:Label><br />

                                                <i title="User Rating" class="glyphicon glyphicon-stats"> </i><asp:Label ID="lblUserRating" runat="server" Text=""></asp:Label><br />

                                                <i title="Contact Number" class="glyphicon glyphicon-phone"> </i><asp:Label ID="lblContactNumber" runat="server" Text=""></asp:Label>

                                            </p>

                                            <!-- Split button -->

                                            <asp:Button ID="btnMessage" runat="server" Text="Message" CssClass="btn btn-success" />
                                                      
                            
                             
                                        </div>
                                    </div>
                                </div>
                            </div>

                                <!-- Description / Product Details--> 
                            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-5">
                                <div class="well well-sm">
                                    <h4> Description: </h4>
                                    <p>
                                        <asp:Label ID="lblDesc" runat="server" Text=""></asp:Label>
                                    </p>

                                </div>
                            </div>



                </div>
            </div>

            <div class="container">
                <div class="row">

                    <!-- Comment Section -->

                    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-10">
                        <div class="well well-sm">
                            <h4>Comments</h4>
                        </div>


                    </div>

                </div>
            </div>



        </div>

    </div>

</div> 
		


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>




推荐答案

您应该在asp.net论坛上发布有关asp的问题以获得更好的支持。

You should post questions about asp in the asp.net forums for better support.

这在论坛顶部用粘性解释。

This is explained in a sticky at the top of the forum.

我会移动你的帖子,但这些论坛在不同的平台上。

I would move your thread but those forums are on a different platform.

https://forums.asp.net/


这篇关于页面加载多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆