471,316 Members | 946 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

A custom button with a collection?

I am trying to create a custom button control for the web that, when clicked,
disables and changes the text of itself and a bunch of other controls (in the
collection). My goal is to end up with a button that prevents the user from
submitting a form back multiple times and also prevents them from submitting
the form and then clicking something else before the postback can finish

What I have is a working button that disables and changes the text of
itself. It generates the <input> tag and associated attributes and it
generates the javascript and the postback event and adds it to the tag. My
hope was to add a collection to the control to generate the javascript to
disable other controls and change their text as well. I wanted to be able to
add it to the properties window (similar to adding Items to a dropdownlist)
and use System.Web.UI.Design.WebControls.ListItemsCollecti onEditor to create
the editor. The problem I am having is adding the collection.

In an attempt to make this work I have added 3 additional classes (basing
this all off of a non-function example of how to create a custom
ListItemsCollectionEditor class I found on the web by Brian Mains). The
"ControlsToDisable" Class is the defines the object that the collection will
store. The "ControlsToDisableCollection" Class inherits from CollectionBase
and its only property is "Item". It also has a few functions for adding
items/ removing items/ etc. The "ControlsToDisableCollectionEditor" Class
(you like the naming convention?) inherits from the ListItemsCollectionEditor
class and sets the type of class to my "ControlsToDisableCollection" Class.
The "Button" Class then has a property that calls the collection. This works
in visual studio and allows me to use the editor to add items and stores
them... however when I run the page with the control on it and get a count of
items in the collection it's 0 and when I go back to the into visual studio
and open up the collection the list is empty. I was under the impression from
the article that the that the collection would be rendered on the page in the
HTML like items in a drop down are rendered, but they are not. I'm not sure
where they are getting stored while I'm in visual studio.

I am perfectly happy to go in a completely different direction with this if
that's what it takes, but I really want to be able to use the
ListItemsCollectionEditor class, as there will be a number of people using
this control and the familiarity means I don't have to repeatedly explain how
to use it. Now if you are still with me (I'm sorry) I'll put the classes
below in the order that I mentioned them. Some stuff has been left out to
help reduce the size of this posting. Thanks in advance for any help that you
can provide.


Imports System.Web.UI
Imports System.ComponentModel

Public Class ControlsToDisable
Private _Name As String
Public Property Name() As String
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property

Public Sub New()
'Do Nothing
End Sub

Public Sub New(ByVal Name As String)
_Name = Name
End Sub

Public Overrides Function tostring() As String
Return _Name
End Function

End Class


Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel

<DefaultProperty("Item")> _
Public Class ControlsToDisableCollection
Inherits CollectionBase
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible), _
PersistenceMode(PersistenceMode.Attribute)> _
Default Public Property Item(ByVal intIndex As Integer) As
Return DirectCast(list.Item(intIndex), ControlsToDisable)
End Get
Set(ByVal Value As ControlsToDisable)
list.Item(intIndex) = Value
End Set
End Property

Public Function Add(ByVal objItem As ControlsToDisable) As Integer
Return list.Add(objItem)
End Function

Public Function Add(ByVal Name As String) As Integer
Return list.Add(New ControlsToDisable(Name))
End Function

Public Function Contains(ByVal objItem As ControlsToDisable) As Boolean
Return list.Contains(objItem)
End Function

Public Sub Insert(ByVal intIndex As Integer, ByVal objItem As
list.Insert(intIndex, objItem)
End Sub

Public Sub Remove(ByVal objItem As ControlsToDisable)
End Sub

End Class


Public Class ControlsToDisableCollectionEditor
Inherits System.Web.UI.Design.WebControls.ListItemsCollecti onEditor

Public Sub New()
End Sub
End Class


Imports System.ComponentModel
Imports System.Web.UI
Imports System.Drawing

<ToolboxBitmap(GetType(System.Web.UI.WebControls.B utton)), _
DefaultEvent("Click"), DefaultProperty("Text"), _
ParseChildren(False), PersistChildren(True)> _
Public Class Button
Inherits System.Web.UI.WebControls.WebControl

Private _ControlListToDisable As New controlsToDisableCollection

<Bindable(True), Browsable(True), Category("Data"), _
GetType(System.Web.UI.Design.WebControls.ListItems CollectionEditor)), _

DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content), _
PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property ControlListToDisable() As ControlsToDisableCollection
Return _ControlListToDisable
End Get
Set(ByVal Value As ControlsToDisableCollection)
_ControlListToDisable = Value
End Set
End Property

Public Sub New()
End Sub

End Class
Jul 22 '05 #1
0 1756

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tom | last post: by
reply views Thread by Sundown | last post: by
19 posts views Thread by Jamey Shuemaker | last post: by
reply views Thread by cranley | last post: by
11 posts views Thread by =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.