Repost: How to determine ID of object in custom web control

J

Jeffrey Frabutt

Sorry about the repost... but my original post had funky characters
that was causing it to get truncated.

I've got a rather simple custom web control that has an object delcared
as HtmlControls.HtmlInputHidden. I set the ID = 'PageNo' and the Name
= 'PageNo'. However, when I look at the page source in the browser,
the object's ID is "WebCtl3_PageNo" and the Name is "WebCtl3:pageNo".
I'm reference the object in javascript as
document.all['WebCtl3_PageNo'] but that seems lame. I get the feeling
that the ID will somehow magically change to "WebCtl2_PageNo" or
"WebCtl4_PageNo" without me realizing it. Is there a better way? I
need to reference it in javascript on the client side. Is there a way
to iterate through document.all and looke for "*PageNo"?
 
A

Anthony Merante

Yea that Webcl2 naming could change depending on what controls you put in
your aspx page.
Your best bet is try reference your control's ClientID property and try to
inject that into your javascript via a method arg or a global javascript
variable.

There were sometimes where i couldnt pass the clientId into my javascript so
I had to resort to this kind of sillyness:
function FindControl(searchString)

{

var formElements = document.forms[0].elements;

for(var i=0;i<formElements.length;i++)

{

if(formElements.id.indexOf(searchString) > -1)

{

return formElements;

}

}

}



sorry about the formatting. Like i said try and use the ClientID.
 

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

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top