Get the id of a rendered control within user control

A

alsu50

Hello All,

I have a user control which has an ASP.Net dropdown, gets filled up
from database, and is supposed to open a document when the selected
index is changed. The control itself is usually nested within a
container on the page.

IE7 treats the act of opening the document from the dropdown as the
popup and blocks it. I do the opening using javascript:

string script = @"<SCRIPT language='javascript'>window.open('" + path +
"');</SCRIPT>";
Response.Write(script);

So I wanted to do the javascript on the client (put it into the
onchange event), but I cannot reference the dropdown, because it's id
is generated by the asp, and becomes
OuterContainer_UserControl_DropdownName.

Question: How do I get to that generated name?
Question2: is there any other, more elegant way to open up the
document?

Thank you.
 
K

Karl Seguin [MVP]

If I understand correctly, you can get a refernece to the server side
control in ASP.NET by the ClientID property:

var ddl = document.getElementById("<%=myDropDown.ClientID%>");

ddl.selectedIndex....


Karl
 
A

alsu50

That worked, thank you.

However, selectedIndex gives me only the number of the selected item.
Is there a way to access the "value" property of the dropdown? That's
where I have the actual file name.


Thank you.
 
A

alsu50

Man, am I lazy or what? The first link on google gave me the answer:

ddl.options[ddl.selectedIndex].value

Thank you, Karl.
 

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
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top