Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

ASP.NET PreInit does not apply SkinID to my ASP.NET Server Controls

$
0
0

I am trying to make a website with reversible themes. At first I was getting nullreferenceexceptions because I was finding my controls outside of any methods. I put them in my PreInit() method and now I can at least get the page to load, but when I click the checkbox that's supposed to change the controls' skin ID's, the body tag's class is changed most of the time, but the skin is's of my server controls never change. I have read that the PreInit() method is not the best place for changing the controls' appearance, but I have found no better ideas, either. I'd appreciate any help I can get. Thanks in advance!

Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) _
	 Handles Me.PreInit
		Dim preferredTheme As HttpCookie = Request.Cookies.Get("PreferredTheme")
		If preferredTheme IsNot Nothing Then
			Page.Theme = preferredTheme.Value
		End If

		Dim bodyControl As HtmlGenericControl = CType(Page.Master.FindControl("Body"), HtmlGenericControl)

		'Controls in the master page itself
		Dim reverse As CheckBox = CType(Page.Master.FindControl("CB_Reverse"), CheckBox)
		Dim reverseToggle As ToggleButtonExtender = CType(Page.Master.FindControl("TBTN_Reverse"), ToggleButtonExtender)
		Dim link As LinkButton = CType(Page.Master.FindControl("LBTN_Copy"), LinkButton)
		Dim treeView As TreeView = CType(Page.Master.FindControl("TreeView1"), TreeView)

		If reverse.Checked = False Then
			bodyControl.Attributes.Add("class", "Lite")
			link.SkinID = "Link"
			reverseToggle.SkinID = "TBCSkin2"
			treeView.SkinID = "TVSkin"
		End If
		If reverse.Checked = True Then
			bodyControl.Attributes.Add("class", "Dark")
			link.SkinID = "Link2"
			reverseToggle.SkinID = "TBCSkin"
			treeView.SkinID = "TVSkin2"
		End If
	End Sub


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>