Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1

    Unanswered: Access custom Web Part "ChromeState" property at RunTime

    Hey guys, I'm having an issue trying to get at the chromestate property for my webparts during run time in an ASP.NET 2.0 app. The webparts themselves are user controls derived from a webpart class. They look, feel and function perfectly, but I would like to trap whether or not their minimized in order to control how many db connections I'm making. Here's an example of how I'm implementing the webparts:

    Code:
    <%@ Control Language="VB" ClassName="myWebPart" %>
    <%@ Implements Interface="System.Web.UI.WebControls.WebParts.IWebPart" %>
    <%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
    <%@ Import Namespace="system.Data.sqlclient" %>
    
    <script runat="server">
        Private _catalogImageUrl As String = String.Empty
        Private _description As String = String.Empty
        Private _subTitle As String = ""
        Private _title As String = "My Web Part"
    
        Public Property CatalogIconImageUrl() As String Implements IWebPart.CatalogIconImageUrl
            Get
                Return _catalogImageUrl
            End Get
            Set(ByVal value As String)
                _catalogImageUrl = value
            End Set
        End Property
    
    
        
        Public Property Description() As String Implements IWebPart.Description
            Get
                Return _description
            End Get
            Set(ByVal value As String)
                _description = value
            End Set
        End Property
      
        Public ReadOnly Property Subtitle() As String Implements IWebPart.Subtitle
            Get
                Return String.Empty
            End Get
        End Property
      
        Public Property Title() As String Implements IWebPart.Title
            Get
                Return _title
            End Get
            Set(ByVal _title As String)
            End Set
        End Property
    
        Public Property TitleIconImageUrl() As String Implements IWebPart.TitleIconImageUrl
            Get
                Return String.Empty
            End Get
            Set(ByVal _title As String)
            End Set
        End Property
    
        Public Property TitleUrl() As String Implements IWebPart.TitleUrl
            Get
                Return String.Empty
            End Get
            Set(ByVal _title As String)
            End Set
        End Property
    
        'Event handlers and such go here
    </script>
    This works pretty slick as far as all the UI elements are concerned. The problem is I have a metric shit ton of these webparts on an administrative page that all need their own datasets. I would like to refrain from making superflous connections to my database from webparts that are not currently visible. This is something stored in the aformentioned "chromestate" property, which I can't seem to get at.

    Basically I'm looking to do something like this:

    Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            If Me.ChromeState = "Normal" Then
                'Perform all my data aware stuff here
            End If
    End Sub
    Any ideas on how to do this?
    Last edited by Teddy; 04-03-06 at 14:05.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    You are using .NET Framework 2.0, right?

    -PatP

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Quote Originally Posted by Pat Phelan
    You are using .NET Framework 2.0, right?

    -PatP
    Yup, I ended up solving it with this:

    Code:
    Imports System.Web.UI.WebControls.Webparts
    
    Public Class clsWebPartTemplate
        Inherits System.Web.UI.UserControl
        Implements System.Web.UI.WebControls.WebParts.IWebPart
    
        Private _webpart As WebPart
    
        Public ReadOnly Property WebPart() As WebPart
            Get
                Dim wpm As WebPartManager
                wpm = WebParts.WebPartManager.GetCurrentWebPartManager(Me.Page)
                WebPart = wpm.WebParts(Me.ID)
            End Get
        End Property
    
        Private _catalogImageUrl As String = String.Empty
        Private _description As String = String.Empty
        Private _subTitle As String = ""
        Private _title As String = ""
    
        Public Property CatalogIconImageUrl() As String Implements IWebPart.CatalogIconImageUrl
            Get
                Return _catalogImageUrl
            End Get
            Set(ByVal value As String)
                _catalogImageUrl = value
            End Set
        End Property
    
    
    
        Public Property Description() As String Implements IWebPart.Description
            Get
                Return _description
            End Get
            Set(ByVal value As String)
                _description = value
            End Set
        End Property
    
        Public ReadOnly Property Subtitle() As String Implements IWebPart.Subtitle
            Get
                Return String.Empty
            End Get
        End Property
    
        Public Property Title() As String Implements IWebPart.Title
            Get
                Return _title
            End Get
            Set(ByVal value As String)
                _title = value
            End Set
        End Property
    
        Public Property TitleIconImageUrl() As String Implements IWebPart.TitleIconImageUrl
            Get
                Return String.Empty
            End Get
            Set(ByVal _title As String)
            End Set
        End Property
    
        Public Property TitleUrl() As String Implements IWebPart.TitleUrl
            Get
                Return String.Empty
            End Get
            Set(ByVal _title As String)
            End Set
        End Property
    
    End Class
    Usage:

    [code]
    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
    If Me.WebPart.ChromeState = PartChromeState.Normal Then
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Quote Originally Posted by Pat Phelan
    You are using .NET Framework 2.0, right?

    -PatP
    Yup, I ended up solving it with this:

    Code:
    Imports System.Web.UI.WebControls.Webparts
    
    Public Class clsWebPartTemplate
        Inherits System.Web.UI.UserControl
        Implements System.Web.UI.WebControls.WebParts.IWebPart
    
        Private _webpart As WebPart
    
        Public ReadOnly Property WebPart() As WebPart
            Get
                Dim wpm As WebPartManager
                wpm = WebParts.WebPartManager.GetCurrentWebPartManager(Me.Page)
                WebPart = wpm.WebParts(Me.ID)
            End Get
        End Property
    
        Private _catalogImageUrl As String = String.Empty
        Private _description As String = String.Empty
        Private _subTitle As String = ""
        Private _title As String = ""
    
        Public Property CatalogIconImageUrl() As String Implements IWebPart.CatalogIconImageUrl
            Get
                Return _catalogImageUrl
            End Get
            Set(ByVal value As String)
                _catalogImageUrl = value
            End Set
        End Property
    
    
    
        Public Property Description() As String Implements IWebPart.Description
            Get
                Return _description
            End Get
            Set(ByVal value As String)
                _description = value
            End Set
        End Property
    
        Public ReadOnly Property Subtitle() As String Implements IWebPart.Subtitle
            Get
                Return String.Empty
            End Get
        End Property
    
        Public Property Title() As String Implements IWebPart.Title
            Get
                Return _title
            End Get
            Set(ByVal value As String)
                _title = value
            End Set
        End Property
    
        Public Property TitleIconImageUrl() As String Implements IWebPart.TitleIconImageUrl
            Get
                Return String.Empty
            End Get
            Set(ByVal _title As String)
            End Set
        End Property
    
        Public Property TitleUrl() As String Implements IWebPart.TitleUrl
            Get
                Return String.Empty
            End Get
            Set(ByVal _title As String)
            End Set
        End Property
    
    End Class
    Usage:

    Code:
    <%@ Control Language="VB" ClassName="myWebPart" Inherits="clsWebPartTemplate" %>
    
    <script>
        Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
            If Me.WebPart.ChromeState = PartChromeState.Normal Then
               'do some data-hog stuff
            End If
        End Sub
    </script>
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •