CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 A generic way to access controls other than by name?

Print topic Send  topic

Author Message
mreeves

Posts: 3
Posted: 03/15/2004, 10:24 PM

Is there a way to access all the controls in a page or form without refering to each of them by name?

For example a way to refer to them generically as an object that is a member of a collection, enumeration, list, array or some such group.

I want to create a re-useable data-driven function that can be placed in any form's "Before Show" (or other) event to examine or override a control's value or other properties.

Thanks,

Mark
View profile  Send private message
peterr


Posts: 5971
Posted: 03/15/2004, 10:45 PM

Yes, add this Function to Classes.asp within the clsControls class.
  Function GetItemByName(ItemName)  
    Dim Element  
    For Each Element In Objects  
      If Objects.Item(Element).Name = ItemName Then  
        Set GetItemByName = Objects.Item(Element)  
        Exit Function  
      End If  
    Next  
    Set GetItemByName = Nothing  
  End Function

Then you should be able to refer to Form's controls like:
Set FormControls = form_name.Controls
FormControls.GetItemByName("control_name").Visible = True

Replace "form_name" and "control_name" with own values.

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
mreeves

Posts: 3
Posted: 03/16/2004, 4:46 PM

Thanks, your solution worked perfectly.


However, after running your solution I have a related question:

I'm looping through all the controls to find all the TextBox controls. When then code below hits a 'Button' control, I ge this message:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'ControlTypeName'

( I received the same error for ControlType)

Sample Code:
If Controls.GetItemByName(control_names(x)).ControlType = csTextBox
then
do some stuff......
end if

Do all controls provide a property or method that will indicate what kind of control I'm currently working with while in the loop?

I need to take different actions on different controls and completely ignore others (buttons).

Thanks,

Mark

View profile  Send private message
peterr


Posts: 5971
Posted: 03/16/2004, 5:04 PM

I'll have to check into this.

Although as a workaround you may be able to use the control names instead. For example name all your buttons "ButtonXYZ" and then check if the "GetItemByName.Name" starts with the word "Button". I haven't tried this though - just an idea...
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
DonB
Posted: 03/16/2004, 5:09 PM

The Button has no 'Name" property. An alternative might be to use the
GetItemByID and populate the Id property of the controls you are interested
in looping through. That, or a Select-Case to bypass the Button (possibly
others without Names).

Any good HTML reference will show which ones have a Name and which don't.

--
DonB

http://www.gotodon.com/ccbth
peterr


Posts: 5971
Posted: 03/17/2004, 12:07 PM

Possibly try:
If TypeName(control) <> "clsButton" Then _   
  If control.ControlType = ccsTextbox Then   
    ' do something  

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
mreeves

Posts: 3
Posted: 03/18/2004, 9:14 AM

Thanks, this helps.


Mark
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.