Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Dynamically testing control ID's


Message #1 by "Mitchell, David" <David.Mitchell@p...> on Wed, 5 Feb 2003 16:11:49 -0500
Hi,

I'm trying to loop through the all of the controls on a page and determine
if the control name contains a certain character. Here is my code:

	  Dim ctl As Control
        Dim ctlId As Integer
        For Each ctl In oForm.Controls
            ctlId = ctl.ID
            If (ctlId.ToString().IndexOf(dType.ToString()) > -1) Then
                Response.Write(ctl.ID & "<br>")
            End If
        Next

dType is actually an int, but it shouldn't be a problem since I am
ToString()ing it before testing IndexOf.

The error I get is:

System.FormatException: Input string was not in a correct format

On the ctlId = ctl.ID line. Any idea what I'm doing wrong here? Is there a
better way to do this?

Thanks,

Dave
Message #2 by "Kailas Tare" <kailast@i...> on Wed, 5 Feb 2003 16:05:30 -0800
Hi Mitchell,

Control's ID property is of type string.
 a) By using 'ctlId =3D ctl.ID' you are trying to assign string to 
integer. Note that you declared ctlId as integer.
 b) Also you don't need to use ctlId.ToString().

I would use following code:

	  Dim ctl As Control
        For Each ctl In oForm.Controls
            If (ctl.ID.IndexOf(dType.ToString()) > -1) Then
                Response.Write(ctl.ID & "<br>")
            End If
        Next

Regards,
Kailas Tare.


-----Original Message-----
From: Mitchell, David [mailto:David.Mitchell@p...]
Sent: Wednesday, February 05, 2003 1:12 PM
To: ASP.NET
Subject: [aspx] Dynamically testing control ID's


Hi,

I'm trying to loop through the all of the controls on a page and 
determine
if the control name contains a certain character. Here is my code:

	  Dim ctl As Control
        Dim ctlId As Integer
        For Each ctl In oForm.Controls
            ctlId =3D ctl.ID
            If (ctlId.ToString().IndexOf(dType.ToString()) > -1) Then
                Response.Write(ctl.ID & "<br>")
            End If
        Next

dType is actually an int, but it shouldn't be a problem since I am
ToString()ing it before testing IndexOf.

The error I get is:

System.FormatException: Input string was not in a correct format

On the ctlId =3D ctl.ID line. Any idea what I'm doing wrong here? Is 
there a
better way to do this?

Thanks,

Dave


  Return to Index