I just found out that removing references to Button Master Page's Button Controls - fixed my problem!
asp.net webforms: BaseClass inheritance / ContentPage controls not accessible
-
02-04-2022 - |
문제
I am working on a multilingual application. For this reason, I created custom BasePage class, which contains overriden InitializeCulture method.
BasePage class inherits System.Web.UI.Page class and all Content Page classess inherits from BasePage. And everything is OK, but one problem exists:
ContentPages can't access it's own controls, when inheriting from BasePage (instead of System.Web.UI.Page).
When I try to reference any control in Content Page code - there is always Nullreference Exception thrown.
Any suggestions about dealing with this problem will be appreciated.
해결책
다른 팁
here's a BasePage class code:
namespace MultiLingualApp {
public class BasePage : System.Web.UI.Page
{
protected override void InitializeCulture()
{
string selectedLanguage = "en-GB";
HttpCookie langCookie = Request.Cookies["langCookie"];
if (langCookie == null)
{
Button btnEnglish = (Button)this.Master.FindControl("btnEnglish");
btnEnglish.Enabled = false;
}
else
{
if (!string.IsNullOrEmpty(langCookie.Values["lang"]))
{
string cookie = langCookie.Values["lang"].ToString();
if (cookie.Equals("en-GB"))
{
selectedLanguage = "en-GB";
Button btnEnglish = (Button)this.Master.FindControl("btnEnglish");
btnEnglish.Enabled = false;
}
else if (cookie.Equals("th-TH"))
{
selectedLanguage = "th-TH";
Button btnThai = (Button)this.Master.FindControl("btnThai");
btnThai.Enabled = false;
}
}
}
if (selectedLanguage != null)
{
UICulture = selectedLanguage;
Culture = selectedLanguage;
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(selectedLanguage);
}
base.InitializeCulture();
}
}
}
제휴하지 않습니다 StackOverflow