473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Get the id of a rendered control within user control

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.

Oct 27 '06 #1
3 1378
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

--
http://www.openmymind.net/
http://www.fuelindustries.com/
<al****@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
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.

Oct 27 '06 #2
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.

Karl Seguin [MVP] wrote:
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

--
http://www.openmymind.net/
http://www.fuelindustries.com/
<al****@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
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.
Oct 27 '06 #3
Man, am I lazy or what? The first link on google gave me the answer:

ddl.options[ddl.selectedIndex].value

Thank you, Karl.

al****@gmail.com wrote:
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.

Karl Seguin [MVP] wrote:
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

--
http://www.openmymind.net/
http://www.fuelindustries.com/
<al****@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
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.
>
Oct 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
2
by: Leeor Chernov | last post by:
Hi I am using a <asp:Table> in a user control I created and in the loop of inserting another user control( a custom Calendar) to the TableCell by the code:...
1
by: SlimFlem | last post by:
I hope this makes sense. Here is what I am attempting. I have an inital generic aspx page that has one custom tag: <web:site id=webSite runat=server/> When this control evaluates, it will...
6
by: Bruce | last post by:
Although I have quite a bit of WinForms experience, I am new to ASP.NET. So don't be surprised by the elementary question. :) I am creating a webpage with a dropdown list that allows the...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
0
by: intrader | last post by:
The situation is that I would like to generate different XHTML depending on where the control is rendered as per example: 1. If control is placed within a <divor <spanoutput <p>something</p>...
0
by: ChopStickr | last post by:
I have a custom control that is embedded (using the object tag) in an html document. The control takes a path to a local client ini file. Reads the file. Executes the program specified in...
0
by: robgallen | last post by:
I have 2 user controls within a master page, and I would like one of them to call a function in the other. All the examples I have seen involve a page communicating with the Master page, or with...
4
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.