If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Access custom Web Part "ChromeState" property at RunTime

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-03-06, 12:57
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
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?
__________________
oh yeah... documentation... I have heard of that.

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

Last edited by Teddy; 04-03-06 at 13:05.
Reply With Quote
  #2 (permalink)  
Old 04-03-06, 13:54
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
You are using .NET Framework 2.0, right?

-PatP
Reply With Quote
  #3 (permalink)  
Old 04-03-06, 17:03
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
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? ***
Reply With Quote
  #4 (permalink)  
Old 04-03-06, 17:04
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
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? ***
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On