Referencing controls by ID in .ascx/usercontrols Options
reykart
Posted: Friday, August 04, 2006 11:17:55 AM
Rank: Devotee

Joined: 7/24/2006
Posts: 33
If I create a .ascx page and use it via a Macro the IDs of elements within the ascx. get renamed when the page is rendered.

For example I have a form field in my usercontrol with an id of "firstName" - when the form get's rendered it has an id of "userControlName2_firstname" - this renaming is not consistent each time the page renders (the number changes)

I am quite sure that this is a fundamental part of ASP.NET/C# - however how can use id's to validate my controls if they are being renamed??

Thanks,

Paul
neehouse
Posted: Friday, August 11, 2006 4:37:48 AM

Rank: Umbracoholic

Joined: 7/20/2006
Posts: 1,066
Location: Charleston, West Virginia, United States
try using the name attribute, and GetElementByName in javascript. Not sure if it will help any..

It sucks that there is no easy solution to the .NET takeover.

I am assuming you are working on field validation, and the .NET IE only validation is not being friendly. Consider adding a validation summary and only showing it (ShowSummary) if the form validation fails on the server. This way, you are sure to catch the validation errors.

PS, you should always code your forms to be handled server side just in case JavaScript is disabled.

Hope this helps.
Case



• 2007/2008 MVP • 2008/2009 MVP • Core Developer • Certified Professional Level I & II •
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.