|
 |
aspx thread: Custom web control problems --please help me--
Message #1 by "Morgan Bell" <morgyb@h...> on Fri, 13 Sep 2002 15:33:18
|
|
I have been working on a web control im my spare time that replicates
(more or less) Microsoft's Digital Dashboard software. I simply want to
manage content in smaller windows that I can open, close, minimize, or
maximize within a browser window. I had written the sub window code
directly into the page before, but managing these windows became
impossible to manage. I decided that the better option was to encapsulate
them in a web control. I had never done this before, and was in fact very
new to the ASP and .NET worlds. Anyway, when I put one window on the page
it works perfectly. When I add more than one window however, they
interact VERY improperly. I think that it is somehow sharing variables
between the controls, but I am not sure. Here is the code:
----------------------------------------------------------------
Imports System
Imports System.Web.UI
Imports System.ComponentModel
Imports System.Web.UI.WebControls
<DefaultProperty("Text"), ToolboxData("<{0}:WebWindow runat=server></
{0}:WebWindow>")> Public Class WebWindow
Inherits System.Web.UI.WebControls.WebControl : Implements
INamingContainer
'CREATE WINDOW PIECES
Public tblWin As New WebControls.Table()
Public tblImages As New WebControls.Table()
Public trImages As New WebControls.TableRow()
Public tdImages1 As New WebControls.TableCell()
Public tdImages2 As New WebControls.TableCell()
Public tr1 As New WebControls.TableRow()
Public tr2 As New WebControls.TableRow()
Public td1_1 As New WebControls.TableCell()
Public td1_2 As New WebControls.TableCell()
Public td2_1 As New WebControls.TableCell()
Public spanData As New HtmlControls.HtmlGenericControl()
Protected WithEvents imgChange As New ImageButton()
Protected WithEvents imgClose As New ImageButton()
'DEFINE WORKING VARIABLES
Dim strSrc As String
Dim bOpen As Boolean = True
Dim sName As String
Dim _text As String
Public Property Src() As String
Get
Return strSrc
End Get
Set(ByVal Value As String)
strSrc = Value
End Set
End Property
Public Property Open() As Boolean
Get
Return bOpen
End Get
Set(ByVal Value As Boolean)
bOpen = Value
End Set
End Property
<Bindable(True), Category("Appearance"), DefaultValue("")> Property
[Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Protected Overrides Sub CreateChildControls()
sName = Me.ID.ToString()
If ViewState(sName) = Nothing Then
bOpen = True
Else
bOpen = CBool(ViewState(sName))
End If
'ASSEMBLE PROPERTIES
tblWin.BorderWidth = Web.UI.WebControls.Unit.Pixel(1)
tblWin.BorderColor = System.Drawing.Color.FromArgb(102, 153, 204)
tblWin.CellPadding = "0"
tblWin.CellSpacing = "0"
tblWin.Width = Me.Width
'SUB TABLE FOR IMAGES
tblImages.BorderWidth = Web.UI.WebControls.Unit.Pixel(1)
tblImages.BorderColor = System.Drawing.Color.FromArgb(102, 153,
204)
tblImages.CellPadding = "1"
tblImages.CellSpacing = "0"
tblImages.Width = Web.UI.WebControls.Unit.Pixel(25)
tdImages1.BackColor = System.Drawing.Color.FromArgb(102, 153, 204)
tdImages1.Height = Web.UI.WebControls.Unit.Pixel(20)
tdImages2.BackColor = System.Drawing.Color.FromArgb(102, 153, 204)
tdImages2.Height = Web.UI.WebControls.Unit.Pixel(20)
tdImages1.Controls.Add(imgChange)
tdImages2.Controls.Add(imgClose)
trImages.Controls.Add(tdImages1)
trImages.Controls.Add(tdImages2)
tblImages.Controls.Add(trImages)
'BUILD THE REST OF THE TABLE
td1_1.BackColor = System.Drawing.Color.FromArgb(102, 153, 204)
td1_1.Height = Web.UI.WebControls.Unit.Pixel(20)
td1_1.ForeColor = System.Drawing.Color.FromArgb(255, 255, 255)
td1_1.Text = _text
td1_2.BackColor = System.Drawing.Color.FromArgb(102, 153, 204)
td1_2.Height = Web.UI.WebControls.Unit.Pixel(20)
td1_2.Style.Item("Text-align") = "right"
td1_2.Width = Web.UI.WebControls.Unit.Percentage(5)
imgChange.ImageUrl = "images/minus.bmp"
imgChange.Height = Web.UI.WebControls.Unit.Pixel(11)
imgChange.Width = Web.UI.WebControls.Unit.Pixel(11)
imgClose.ImageUrl = "images/close.bmp"
imgClose.Height = Web.UI.WebControls.Unit.Pixel(11)
imgClose.Width = Web.UI.WebControls.Unit.Pixel(11)
'ADD BODY DATA TO THE COMPONENT
spanData.InnerHtml = "<iframe scrolling='no' frameborder='0'
src='" & strSrc & "' style='position:relative; top:0px; left:0px;
width:100%; height:100%' marginwidth='0px'><iframe>"
td2_1.ColumnSpan = "2"
'ASSEMBLE THE TABLE
td1_2.Controls.Add(tblImages)
tr2.Controls.Add(td2_1)
tr1.Controls.Add(td1_1)
tr1.Controls.Add(td1_2)
tblWin.Controls.Add(tr1)
tblWin.Controls.Add(tr2)
td2_1.Controls.Add(spanData)
Controls.Add(tblWin)
If bOpen = True Then
'IF THE WINDOW IS OPEN, DISPLAY THE WHOLE THING
tblWin.Height = Me.Height
tr2.Visible = True
spanData.Visible = True
td2_1.Visible = True
imgChange.ImageUrl = "images/minus.bmp"
bOpen = True
viewState(sName) = "true"
Else
'IF THE WINDOW IS CLOSED, HIDE THE BODY HALF
tblWin.Height = Unit.Pixel(20)
tr2.Visible = False
spanData.Visible = False
td2_1.Visible = False
imgChange.ImageUrl = "images/plus.bmp"
bOpen = False
viewState(sName) = "false"
End If
End Sub
Private Sub imgChange_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles imgChange.Click
If bOpen = False Then
'IF IT IS CLOSED, OPEN IT
tblWin.Height = Me.Height
tr2.Visible = True
spanData.Visible = True
td2_1.Visible = True
imgChange.ImageUrl = "images/minus.bmp"
bOpen = True
viewState(sName) = "true"
Else
'IF IT IS OPEN, CLOSE IT
tblWin.Height = Web.UI.WebControls.Unit.Pixel(20)
tr2.Visible = False
spanData.Visible = False
td2_1.Visible = False
imgChange.ImageUrl = "images/plus.bmp"
bOpen = False
viewState(sName) = "false"
End If
End Sub
Private Sub imgClose_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles imgClose.Click
'HIDE CONTROL
Me.Visible = False
End Sub
End Class
---------------------------------------------------------------
I build the project, and then add it to the toolbox. Placing one on the
form is great, but more than one will not work.
Any help that I can get would be very appreciated. Thanks in advance.
Maynard
Message #2 by "Morgan Bell" <morgyb@h...> on Tue, 17 Sep 2002 16:20:52
|
|
Thanks everyone for all the help, but I found the problem.
Maynard
|
|
 |