invalid characters in 'ID' web control property

G

Gabe Moothart

Hi,
In my asp.net app, I create several controls dynamically, and set their
'ID' property to a value stored in a database, so I can reference them
later. So far so good.

This database field, however, might contain characters which are illegal
in the 'ID' property. It took me quite a while to figure out that the
reason one of my controls was not working (but the others were) was
because there was a ':' in the ID property. Apparently, instead of
raising an exception (which I would have preferred), asp.net silently
converted the ':' to '_' - changing the name of my component.

After some experimentation, I noticed that, in the property editor, an
exception is raised when I try to create an ID field with any of the
characters '-', ':', and '?' (I'm sure there are others, too). However,
when setting the ID property at runtime, '-' and '?' are passed through
unchanged, and seem to work; while ':' is converted to '_'.

Is there a list somewhere of characters I need to avoid in the 'ID'
attribute? Or, better yet, a function which strips them out of a string?

TIA,
Gabe
 
G

Guest

Gabe, I don't know if there is a list of characters or a function to strip them, but I'd be very nervous about using *data* to create any sort of ID field. I understand wanting to access them later, but can't you use a column name or something you "trust"? Otherwise, even if there is a strip function you trust, you'll run the risk of two different data fields "stripping" to the same ID. Just my $.02.

----- Gabe Moothart wrote: -----

Hi,
In my asp.net app, I create several controls dynamically, and set their
'ID' property to a value stored in a database, so I can reference them
later. So far so good.

This database field, however, might contain characters which are illegal
in the 'ID' property. It took me quite a while to figure out that the
reason one of my controls was not working (but the others were) was
because there was a ':' in the ID property. Apparently, instead of
raising an exception (which I would have preferred), asp.net silently
converted the ':' to '_' - changing the name of my component.

After some experimentation, I noticed that, in the property editor, an
exception is raised when I try to create an ID field with any of the
characters '-', ':', and '?' (I'm sure there are others, too). However,
when setting the ID property at runtime, '-' and '?' are passed through
unchanged, and seem to work; while ':' is converted to '_'.

Is there a list somewhere of characters I need to avoid in the 'ID'
attribute? Or, better yet, a function which strips them out of a string?

TIA,
Gabe
 
G

Gabe Moothart

Bill said:
I'd be very nervous about using *data* to create any sort of ID field. I understand wanting to access them later, but can't you use a column name or something you "trust"? Otherwise, even if there is a strip function you trust, you'll run the risk of two different data fields "stripping" to the same ID.

Bill,
Yeah, you're right about the dangers of naming controls based on
user-entered data. It was a bad idea in the first place :). The key
field of the database in question is a guid type, so I'm considering
using that, instead of the 'name' field, for the ID. I've tried it, and
it works

However, since the property editor doesn't allow the '-' character or
leading numeric digits (both of which can appear in guids) in the 'ID'
field, I'm a little afraid that I'm doing something that is not
supported and may break in a future version of the Framework.

I'd feel better if I could find something official from Microsoft on
what is allowed in the 'ID' field and what is not.

Gabe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top