Page_Load 中的新用户控件在 Webform 中没有 css

New userControl in Page_Load don't have css in Webform

在一个页面中,我在 Page_Load 中添加了一个新的 userControl。 但是当我加载页面时,我看到我的控件但是 CSS 坏了,它显示为一个没有我的 css.

的简单文本框

代码如下:

if (Contexte.GetLanguage == "UK")
{
    UC_DooFinder = (UserControl)Page.LoadControl("~/inc/DooFinder.ascx");
    UC_DooFinder.ID = "UC_DOOFINDER";
    this.Controls.Add(UC_DooFinder);
    UC_Recherche.Dispose();
}

"this" 是一个名为 "Header.ascx" 的页面,它包含在我的主页中。

但是如果我在前面包含 userControl,它就可以工作。 但出于某些原因,我需要从 .cs 中调用它。

我找到了解决方案:我在 page_init 事件中初始化我的 userControls,现在它工作正常。

谢谢。