473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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
processing.

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.

------------ControlsToDisable----------------------------------------

Imports System.Web.UI
Imports System.ComponentModel

Public Class ControlsToDisable
Private _Name As String
Public Property Name() As String
Get
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

------------ControlsToDisableCollection------------------------------

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
ButtonsToDisable
Get
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
ControlsToDisable)
list.Insert(intIndex, objItem)
End Sub

Public Sub Remove(ByVal objItem As ControlsToDisable)
list.Remove(objItem)
End Sub

End Class

------------ControlsToDisableCollectionEditor------------------------

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

Public Sub New()
MyBase.New(GetType(ControlsToDisableCollection))
End Sub
End Class

------------Button---------------------------------------------------

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"), _
Editor(GetType(controlsToDisableCollection),
GetType(System.Web.UI.Design.WebControls.ListItems CollectionEditor)), _

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

Public Sub New()
MyBase.New(HtmlTextWriterTag.Input)
End Sub

End Class
Jul 22 '05 #1
0 1885

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: PK | last post by:
Hello, I am looking for help on the following. I'm trying to create a custom browser toolbar button that will do a few things. One that I'm trying to do at the moment is just simply return the...
2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
0
by: Tom | last post by:
I am developing a page that will contain multiple instances of a Composite Custom Control that i have developed. The problem is that the user will determine at run time how many of the control...
0
by: Sundown | last post by:
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...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
0
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design...
0
by: cranley | last post by:
Hi. I'm currently building a custom control. On my custom control is a colleciton property which I wish to edit with the VS.NET collection editor. So far I have everything working as planned,...
11
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.