>I believe you have at least one Control with a null id.
How can the ID be null? If the control itself is not null, and the ID is
a string (according to the SDK), then surely the ID should give you an
empty string. Please explain how it can be null.
I changed my code to...
if ((ctlId != null) && (ctlId.StartsWith("X_"))) {
.... and it works fine now. So you were absolutely correct, although I
still don't really understand how the situation could arise.
> Unfortunately, it is
>not an error to concatenate a string with a null string. So:
>
>Trace.Warn("ctlId = @" + ctlId + "@");
>
>will not throw an exception. Neither will:
>
>if (ctlId != "")
>
>If ctlId is null, it will evaluate to true (ctlId is not equal to an empty
>string).
Hmm, that's really stupid. Still forewarned is forearmed as they say
>Also, you should be awaare that the Page.Controls Collection is only a
>Collection of those Controls immediately under the Page. You would need a
>recursive function to get at all the nested Controls in the Page.
Ha, here's me thinking that it's not an issue in this case, and feeling
smug that I didn't make *that* mistake, when I realised that the
controls I wanted were all inside a placeholder, and so didn't show up
in the loop I coded. I needed to loop over the placeholder's control
collection.
Ho hum. Thanks for the warning there, you saved me hours of debugging!!
--
Alan Silver
(anything added below this line is nothing to do with me)