473,385 Members | 1,379 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,385 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 1883

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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...

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.