Skip to content

Instantly share code, notes, and snippets.

@TekkGuy
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TekkGuy/8866439 to your computer and use it in GitHub Desktop.
Save TekkGuy/8866439 to your computer and use it in GitHub Desktop.
These methods allow for the collapse and expanding of DNNPanels through the modification of cookies.
'''-------------------------------------------------------------------------------------------------
''' <summary> Sets expended status of collapsible panels within container. </summary>
'''
''' <param name="p_objContainer"> The object container. </param>
''' <param name="p_boolExpanded"> True to expend. </param>
'''
''' <history>
''' Date Developer Description
''' ============================================================================================
''' 02/07/2014 [Ben Santiago] Created
''' </history>
'''-------------------------------------------------------------------------------------------------
Public Shared Sub SetAllPanelsAsExpanded(ByVal p_objContainer As Control, ByVal p_boolExpanded As Boolean)
'***************************************
' Initialize Variables
'***************************************
Dim strLiteralText As String
Dim strHeaderID As String
Dim intIDIndexStart As Integer
Dim intIDIndexStop As Integer
'***************************************
' Process Each Control In Container (Search For Literals Containing H2)
'***************************************
For Each objControl As Control In p_objContainer.Controls
If (objControl.GetType().ToString() = "System.Web.UI.ResourceBasedLiteralControl") Then
'***************************************
' Extract Literal Text
'***************************************
strLiteralText = CType(objControl, LiteralControl).Text.Trim()
'***************************************
' Check If Literal Starts w/ H2 Tag
'***************************************
If ((strLiteralText.IndexOf("<H2 ") > -1) OrElse (strLiteralText.IndexOf("<h2 ") > -1)) Then
'***************************************
' Extract H2 Tag
'***************************************
intIDIndexStart = strLiteralText.IndexOf("<H2 ")
If (intIDIndexStart = -1) Then intIDIndexStart = strLiteralText.IndexOf("<h2 ")
strLiteralText = strLiteralText.Substring(intIDIndexStart, strLiteralText.IndexOf(">", intIDIndexStart) + 1)
'***************************************
' Validate Header Has "dnnFormSectionHead" Class
'***************************************
If (strLiteralText.ToUpper().IndexOf("CLASS=""DNNFORMSECTIONHEAD""") > -1) Then
'***************************************
' Extract Header ID
'***************************************
intIDIndexStart = strLiteralText.ToUpper().IndexOf("ID=") + 4
intIDIndexStop = strLiteralText.IndexOf("""", intIDIndexStart)
strHeaderID = strLiteralText.Substring(intIDIndexStart, intIDIndexStop - intIDIndexStart)
'***************************************
' Collapse/Expande Section
'***************************************
Utils.SetPanelAsExpanded(strHeaderID, p_boolExpanded)
End If
End If
End If
Next
End Sub
'''-------------------------------------------------------------------------------------------------
''' <summary> Set expended status of collapsible panel. </summary>
'''
''' <param name="p_strSectionHeaderID"> Section header ID. </param>
''' <param name="p_boolExpanded"> True to expanded. </param>
'''
''' <history>
''' Date Developer Description
''' ============================================================================================
''' 02/07/2014 [Ben Santiago] Created
''' </history>
'''-------------------------------------------------------------------------------------------------
Public Shared Sub SetPanelAsExpanded(ByVal p_strSectionHeaderID As String, ByVal p_boolExpanded As Boolean)
'***************************************
' Initialize Variables
'***************************************
Dim objHTTPContext As HttpContext = HttpContext.Current
Dim objHTTPCookie As HttpCookie
'***************************************
' Create New Cookie Object
'***************************************
objHTTPCookie = New HttpCookie(p_strSectionHeaderID)
objHTTPCookie.HttpOnly = False
objHTTPCookie.Value = If(p_boolExpanded, "true", "false")
'***************************************
' Save Cookie (Overwrite Exiting)
'***************************************
objHTTPContext.Response.Cookies.Add(objHTTPCookie)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment