문제
CodeBehind에서 SkinId를 변경할 수있는 방법이 있습니까? 다른 속성을 설정하는 동안 시도했지만 작동하지 않습니다. 피부는 적용되지 않습니다.
public GlobalImageButtonType Skin {
get { return _skin; }
set
{
_skin = value;
this.SkinID = _skin.ToString();
this.CommandName = _skin.ToString();
LoadDefaultValues();
}
}
또한 루프를 통한 Page.Contols를 시도했지만 Page_OnPreinit 이벤트에서는 Controls Collection이 비어 있습니다.
ASPX 페이지보다 다른 곳에서 SkinID를 변경할 수 있습니까?
감사
해결책
스킨 디드 프로그래밍 방식으로 만 변경할 수 있습니다 onpreinit - 컨트롤을 위해 이것을 시작하는 유일한 옵션은 페이지에 있습니다. onpreinit.
정상적인 상황에서 .통제 수단 그 단계에서 사용할 수 있어야합니다.
경우에 따라 .주인 페이지 :
/*
* HACK: need to ensure master controls are instantiated first.
* */
MasterPage root = this.Master;
while (root.Master != null)
root = root.Master;
InvokeControlPreInit(Controls);
이제 스키닝이 필요한 컨트롤을 가질 수 있습니다. 일부 인터페이스 (iruntimeskinablecontrol)를 구현하여 자신의 스킨을 할당 할 수 있습니다.
private void InvokeControlPreInit(ControlCollection controls)
{
foreach (Control control in controls)
{
IRuntimeSkinableControl skinableControl;
if (null != (skinableControl = control as IRuntimeSkinableControl))
skinableControl.OnPreInit();
if (string.IsNullOrEmpty(control.SkinID) && control.Controls.Count > 0)
InvokeControlPreInit(control.Controls);
}
}
컨트롤은 그렇게 적용됩니다.
public class UserControl : System.Web.UI.UserControl, IRuntimeSkinableControl
{
public virtual void OnPreInit()
{
//assign this.SkinID
}
}
제휴하지 않습니다 StackOverflow