Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2006

Tip: Looking for answers? Try searching our database.

altering .UniqueID

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jason.hau@gmail.com - 22 Sep 2006 12:05 GMT
Is there any way to alter this? I am aware that it's read only.
Essentially the problem is that I have a webcontrol that dynamically
creates a textbox and a requiredfieldvalidator control with the
validator validating the textbox. This worked fine in my test harness
and works fine in my other projects using master page based pages when
in IE but in Firefox, the other project doesn't work. I've been able to
narrow it down to teh fact that we've got a preappend on the ID of the
controls of "_ctl0" and as an underscore isn't a valid start character,
firefox doesn't run the javascript (quite rightly).
I'd prefer to alter this within the original code that creates the sub
controls rather than hack it in the other project as it's to be part of
a common library for use elsewhere.
Edwin Knoppert - 22 Sep 2006 14:14 GMT
Can you try the name tag instead?

> Is there any way to alter this? I am aware that it's read only.
> Essentially the problem is that I have a webcontrol that dynamically
[quoted text clipped - 8 lines]
> controls rather than hack it in the other project as it's to be part of
> a common library for use elsewhere.
RVB - 22 Sep 2006 14:49 GMT
Not really an option, the validators work by writing a javascript array
called Page_Validators, automatically generated by .NET itself. This is
then referenced by another automatically generated item, a javascript
file, which it pulls out using a handler via
webresource.axd?somerandomguid. As such, can't really alter the
javascript call itself where the validation fires off nor is it really
practical to try and reverse engineer this js file.
I have found another ID reference: ClientID but again, read only. The
only one which you appera to be able to alter is ID which is of no use
whatsoever. All I want is to be able to change the ID, I fail to
understand why this is so hard, especially as I keep hearing "oh yes,
validators have been fixed to work with Firefox in .NET 2.0".
BTW, Test Harness works in Firefox because it lacks the auto
pre-append. I'm not exactly sure where this auto generated _ctl0 is
coming from. Admittedly the control sits inside an ascx (which has a
normal id) and then itself with a contentplaceholder based off a
seperate master page. If I knew where that was coming from I would be
able to override it but the control has an ID, the placeholder has an
ID and I'm at a loss to determine why it's appearing.
> Can you try the name tag instead?
>
[quoted text clipped - 10 lines]
> > controls rather than hack it in the other project as it's to be part of
> > a common library for use elsewhere.
Edwin Knoppert - 22 Sep 2006 16:45 GMT
I don't have ff installed but i often needed to use document.GetEl.. ByID(
'name of control') to get an object refer.
Is the quoted way not a solution?

> Not really an option, the validators work by writing a javascript array
> called Page_Validators, automatically generated by .NET itself. This is
[quoted text clipped - 29 lines]
>> > controls rather than hack it in the other project as it's to be part of
>> > a common library for use elsewhere.
Edwin Knoppert - 22 Sep 2006 16:46 GMT
Like:
var o = document.getElementById('<%=txt_Index.ClientID%>');
o.value = ....

> Not really an option, the validators work by writing a javascript array
> called Page_Validators, automatically generated by .NET itself. This is
[quoted text clipped - 29 lines]
>> > controls rather than hack it in the other project as it's to be part of
>> > a common library for use elsewhere.
RVB - 22 Sep 2006 16:56 GMT
As far as I'm aware, it's not, reason being that the actual javascript
array creation is done by the .NET framework automatically if it
detects that there are validators in the validator collection. It is
doing essentially the same as your snippet, it just outputs the actual
clientid for the validator control (at that point rendered as a span)
instead of doing a codebehind call. I can't actually get alter this
array and in any case, it wouldn't work because of the actual format of
the ID:
Using your example, "txt_Index.ClientID" would equate to
"_ctl0_txt_Index1". As it starts with an underscore, firefox doesn't
recognize it as a correct ID. So, as you can see, the problem stems
from the whole auto-generation of the clientID. Fix that and you'd be
laughing.
Several other people have apparently got around this by doing
control.ClientID = control.ClientID.Replace("_","") but I find that
highly unlikely as you -cannot- set the ClientID property, nor the
UniqueID.

> Like:
> var o = document.getElementById('<%=txt_Index.ClientID%>');
[quoted text clipped - 33 lines]
> >> > controls rather than hack it in the other project as it's to be part of
> >> > a common library for use elsewhere.
Edwin Knoppert - 25 Sep 2006 09:02 GMT
I had the thought the quoted situation might have helped
(getElementById('...')
Have you actually tried this approach?

> As far as I'm aware, it's not, reason being that the actual javascript
> array creation is done by the .NET framework automatically if it
[quoted text clipped - 58 lines]
>> >> > of
>> >> > a common library for use elsewhere.
RVB - 25 Sep 2006 16:45 GMT
I -cannot- alter the javascript as it is auto-generated and the API
does not provide me with an entry point to do so.

I have gotten a touch further, the original _ctrl0 was coming from the
ID of the Master.ID property on the page itself. When I altered the ID
of the Page.Master property, I was able to remove the "_" from the
generated clientID so it ends up as "ctrl0_txtSomething_ctrl1" which,
as far as I can see is definately a valid ID which can be passed to the
document.getElementById function. However, still doesn't work.

Additionally, I've crossposted to the javascript newsgroup but has
anyone hit this before in .NET?

> I had the thought the quoted situation might have helped
> (getElementById('...')
[quoted text clipped - 62 lines]
> >> >> > of
> >> >> > a common library for use elsewhere.
Edwin Knoppert - 26 Sep 2006 10:26 GMT
>I -cannot- alter the javascript as it is auto-generated and the API does
>not provide me with an entry point to do so.

That was not my point.
I asked if you tried to obtain an object using this getElementById('...')
often people directly refer to a control in js, which not always works.
Obtaining a refer to the control using getElementById('...') is imo better.

So.. a simple:
alert( getElementById(' your clientid stuff here ') );

Does that result in an object or null?

>I -cannot- alter the javascript as it is auto-generated and the API
> does not provide me with an entry point to do so.
[quoted text clipped - 89 lines]
>> >> >> > of
>> >> >> > a common library for use elsewhere.
RVB - 26 Sep 2006 10:39 GMT
Sorry for the mix up.
I've actually got a touch further in that it now does populate the
array correctly but the actual validation function isn't being called.
I've checked with various formats of IDs and it definately wasn't
picking it up when using an underscore as the beginning character, i.e.
the array was empty. Got it to output without that beginning underscore
and it now picks up the elements. Now just seeing why it doesn't
register the validator.IsValid property as false.

> >I -cannot- alter the javascript as it is auto-generated and the API does
> >not provide me with an entry point to do so.
[quoted text clipped - 102 lines]
> >> >> >> > of
> >> >> >> > a common library for use elsewhere.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.