473,698 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the id that Javascript uses for a server control?

When I view-source I see that ASP.NET 2 has given the control:
lstActivities no id but a
name="ctl00$Con tentPlaceHolder $lstActivities"

How can I get the client-side id (or name) of a HTML element? (the id
that is seen by javascript). What should I put in between the server
tags: CheckStyle('<% %>') such that the div id="tdStyle" is displayed
when the ListBox has an item with text 'Awarded mandate'?

The function init runs when the page is loaded.

I realise that this can be done with server code but I have needed to
know the client-side ids of html elements in the past so I'll still
post the question.
<html>
<head>
<script type="text/javascript">
onload=init
function init()
{
CheckStyle('<% %>')
}
function CheckStyle(oSel )
{

document.getEle mentById('tdSty le').style.disp lay=(oSel.optio ns[oSel.selectedIn dex].text=='Awarded
mandate')?'bloc k':'none'
}
</script>
</head>
<body>
<asp:ListBox ID="lstActiviti es" runat="server"
AutoPostBack="T rue"
OnSelectedIndex Changed="lstAct ivities_Selecte dIndexChanged"
onblur="CheckSt yle(this)">
</asp:ListBox>

<div id="tdStyle" style="display: none;">
<strong>Style </strong><br /><br />
<asp:RadioButto nList ID="rblStyle" runat="server">
<asp:ListItem Text="Active" Value="A" />
<asp:ListItem Text="Passive" Value="P" />
<asp:ListItem Text="Unconstra ined" Value="U" />
<asp:ListItem Text="Undisclos ed" Value="N" />
</asp:RadioButton List>
</div>
</body>
</html>
Feb 6 '07 #1
2 2011
Use

yourControl.Cli entID

from your asp.net code.

"mark4asp" <ma******@gmail .comwrote in message
news:9a******** *************** *********@4ax.c om...
When I view-source I see that ASP.NET 2 has given the control:
lstActivities no id but a
name="ctl00$Con tentPlaceHolder $lstActivities"

How can I get the client-side id (or name) of a HTML element? (the id
that is seen by javascript). What should I put in between the server
tags: CheckStyle('<% %>') such that the div id="tdStyle" is displayed
when the ListBox has an item with text 'Awarded mandate'?

The function init runs when the page is loaded.

I realise that this can be done with server code but I have needed to
know the client-side ids of html elements in the past so I'll still
post the question.
<html>
<head>
<script type="text/javascript">
onload=init
function init()
{
CheckStyle('<% %>')
}
function CheckStyle(oSel )
{

document.getEle mentById('tdSty le').style.disp lay=(oSel.optio ns[oSel.selectedIn dex].text=='Awarded
mandate')?'bloc k':'none'
}
</script>
</head>
<body>
<asp:ListBox ID="lstActiviti es" runat="server"
AutoPostBack="T rue"
OnSelectedIndex Changed="lstAct ivities_Selecte dIndexChanged"
onblur="CheckSt yle(this)">
</asp:ListBox>

<div id="tdStyle" style="display: none;">
<strong>Style </strong><br /><br />
<asp:RadioButto nList ID="rblStyle" runat="server">
<asp:ListItem Text="Active" Value="A" />
<asp:ListItem Text="Passive" Value="P" />
<asp:ListItem Text="Unconstra ined" Value="U" />
<asp:ListItem Text="Undisclos ed" Value="N" />
</asp:RadioButton List>
</div>
</body>
</html>


Feb 6 '07 #2
CheckStyle('<%= lstActivities.C lientID %>')

--
Milosz
"mark4asp" wrote:
When I view-source I see that ASP.NET 2 has given the control:
lstActivities no id but a
name="ctl00$Con tentPlaceHolder $lstActivities"

How can I get the client-side id (or name) of a HTML element? (the id
that is seen by javascript). What should I put in between the server
tags: CheckStyle('<% %>') such that the div id="tdStyle" is displayed
when the ListBox has an item with text 'Awarded mandate'?

The function init runs when the page is loaded.

I realise that this can be done with server code but I have needed to
know the client-side ids of html elements in the past so I'll still
post the question.
<html>
<head>
<script type="text/javascript">
onload=init
function init()
{
CheckStyle('<% %>')
}
function CheckStyle(oSel )
{

document.getEle mentById('tdSty le').style.disp lay=(oSel.optio ns[oSel.selectedIn dex].text=='Awarded
mandate')?'bloc k':'none'
}
</script>
</head>
<body>
<asp:ListBox ID="lstActiviti es" runat="server"
AutoPostBack="T rue"
OnSelectedIndex Changed="lstAct ivities_Selecte dIndexChanged"
onblur="CheckSt yle(this)">
</asp:ListBox>

<div id="tdStyle" style="display: none;">
<strong>Style </strong><br /><br />
<asp:RadioButto nList ID="rblStyle" runat="server">
<asp:ListItem Text="Active" Value="A" />
<asp:ListItem Text="Passive" Value="P" />
<asp:ListItem Text="Unconstra ined" Value="U" />
<asp:ListItem Text="Undisclos ed" Value="N" />
</asp:RadioButton List>
</div>
</body>
</html>
Feb 6 '07 #3

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

Similar topics

1
3848
by: jarit | last post by:
Hi, Found these coding guidelines for C#, HTML, Javascript, Java, HTML, PL/SQL, T-SQL, VB and VBScript. Well written and free to download. www.demachina.com/products/swat Jeroen
1
6809
by: ido | last post by:
Hi all this is my first post here :) I would like to know something about using javascript programaticaly The thing is i have this web site on which when i press a button i uses a function of javascript.. says exactly this in source <a href="javascript:np('1')" ... now when i am on that page and i type in my browsers comand line (o address field)
11
4992
by: trinitypete | last post by:
Hi all, I have a user control that uses control literal to build a heading with a link, and a div containing links below. As the link heading is hit, I want to change the style of the div, making it visible or not. Yep you guessed it, expanding tree type functionality. The header has an onclick event onclick='Doexpandcollapse
3
2466
by: qwerty | last post by:
I´m new to ASP.Net. My workmate has some experience with it. He claimed that in ASP.Net working with frames is much simpler than it was ASP. I asked explanation but he couldn't give me such. (a button inside a-tag with attribute target isn't anything new relating ASP.Net, its same old HTML). He claimed that you could change another page´s controls´s property´s value from another frame by using this method: ' Page "Bottom"
2
1766
by: Stu | last post by:
Hi, I have a javascript that needs to reference a server control (Listbox1) to check if an item is selected but the server controls are renamed '_ctl0:mainbody:Listbox1' when displayed in a masterpage. Unfortunately the script needs to run whilst displayed in a number of different areas on the masterpage. Is there any way of getting the altered client side control ID at runtime?
2
3171
by: kplkumar | last post by:
I have created a asp.net date picker control using Javascript. I wanted to do this to avoid doing post back when the calendar window is launched. It works like charm. But the challenge is - the control does not use any asp.net controls like button or textfield. It uses html "input" for the text field and the button. So after the user has choosen the date and the date is populated in the textfield, I am not able to get the value from the...
15
3616
by: mc | last post by:
I'm writing an app for managing Task Lists, I'm trying to add some controls to a form that I can use to link tasks, my original intention was to: - Add two list boxes, one listing "all Tasks" and the other listing "Linked Tasks", I have two buttons which in javascript move items from the first list into the second. Then when a user clicks a thrid button I would like to save this data.
4
3867
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I am using a master page senerio. The erro I'm getting is 'busyBox' is not a member of 'ASP.login2_aspx'
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.