页面加载事件未在ascx控件中触发 [英] page load event not firing in ascx control

查看:84
本文介绍了页面加载事件未在ascx控件中触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



i有一个母版页文件,它从后面的代码调用用户控制页面(AdminleftNav.ascx)filr。

但是page_load事件在ascx文件中第一次触发。

如果我刷新页面,它不会触发。

这里是代码后面的管理代码:

  if (HttpRuntime.Cache.Get(  LeftNavigation _ + loggedUser.UserId.ToString())==  null 
{
HttpRuntime.Cache.Insert( LeftNavigation _ + loggedUser.UserId.ToString(),Page .LoadControl( AdminLeftNav.ascx), null ,DateTime.Now.AddMinutes( 1000 ),System.Web.Caching.Cache.NoSlidingExpiration );
}
var userControl =(UserControl)HttpRuntime.Cache.Get( LeftNavigation _ + loggedUser.UserId.ToString());
phLeftNav.Controls.Add(userControl);







我的page_load功能代码是:

 受保护  void  Page_Load( object  sender,EventArgs e)
{
var loggedUser = CommonFunctions.GetLoggedUser();

if (!IsPostBack)
{
try
{
if (loggedUser!= null
{
companyId =( int )loggedUser.CompanyId;

var company = _companyService。 Single (x = > x.CompanyId == companyId);

if (company!= null
imgCompanyLogo.ImageUrl = ../ images / companylogo / + company.CompanyLogoPath;

var NewVacancies = _jobService.Find(x = > x.JobStatusId == 1 || x.JobStatusId == 6 )。Count();

if (NewVacancies > 0
{
phJobWaitingForApproval.Visible = true ;
phNoJobWaitingForApproval.Visible = false ;
}
}

}
catch (例外情况)
{
_log.Log(ex);
}
}
}

解决方案



i有找到我的问题的解决方案。



在用户控制页面中,在构造函数中添加以下行。



this.Load + = Page_Load中;

Hi friends,

i have one master page file which calls user control page (AdminleftNav.ascx) filr from code behind.
but the page_load event firing first time in ascx file.
if i refresh the page, it does n't firing.
here is my admin code behind code:

if (HttpRuntime.Cache.Get("LeftNavigation_" + loggedUser.UserId.ToString()) == null)
                   {
                       HttpRuntime.Cache.Insert("LeftNavigation_" + loggedUser.UserId.ToString(), Page.LoadControl("AdminLeftNav.ascx"), null, DateTime.Now.AddMinutes(1000), System.Web.Caching.Cache.NoSlidingExpiration);
                   }
                   var userControl = (UserControl)HttpRuntime.Cache.Get("LeftNavigation_" + loggedUser.UserId.ToString());
                   phLeftNav.Controls.Add(userControl);




my page_load function code is :

protected void Page_Load(object sender, EventArgs e)
        {
            var loggedUser = CommonFunctions.GetLoggedUser();

            if (!IsPostBack)
            {
                try
                {
                    if (loggedUser != null)
                    {
                        companyId = (int)loggedUser.CompanyId;

                        var company = _companyService.Single(x => x.CompanyId == companyId);

                        if (company != null)
                            imgCompanyLogo.ImageUrl = "../images/companylogo/" + company.CompanyLogoPath;

                        var NewVacancies = _jobService.Find(x => x.JobStatusId == 1 || x.JobStatusId == 6).Count();

                        if (NewVacancies > 0)
                        {
                            phJobWaitingForApproval.Visible = true;
                            phNoJobWaitingForApproval.Visible = false;
                        }
                    }

                }
                catch (Exception ex)
                {
                    _log.Log(ex);
                }
            }
        }

解决方案

Hi,
i have found solution for my problem.

in user control page, within constructor add the following line.

this.Load+=Page_Load;


这篇关于页面加载事件未在ascx控件中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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