473,387 Members | 1,578 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.

How does javascript identify controls on asp.net pages?

I'd like a javascript routine to calculate totals of some column in a
table. But the table is in a asp.net page, and when I do a 'view
source', I see that the names of the controls are not what I expect.
Where can I get info on using javascript with asp.net textbox fields?
Thanks,
Marv
Jun 27 '08 #1
4 902
<CO*********@lycos.comwrote in message
news:69**********************************@x41g2000 hsb.googlegroups.com...
I'd like a javascript routine to calculate totals of some column in a
table. But the table is in a asp.net page, and when I do a 'view
source', I see that the names of the controls are not what I expect.
Where can I get info on using javascript with asp.net textbox fields?
If you have an <asp:TextBox /control called MyTextBox, you refer to it
server-side just with its name e.g.

MyTextBox.Text = "Hello";

However, as you've discovered, this almost certainly isn't what ASP.NET
calls the control by the time it's rendered to the client browser.

Thankfully, this is easily solved. Simply "inject" the name of the control
into your JavaScript dynamically by means of its ClientID property, e.g.

<script type="text/javascript">
var myTextBox = document.getElementById('<%=MyTextBox.ClientID%>') ;
</script>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #2
I'd like a javascript routine to calculate totals of some column in a
table. But the table is in a asp.net page, and when I do a 'view
source', I see that the names of the controls are not what I expect.
Javascript has no concept of ASP.net controls as they are server-side
concepts.

Javascript, being client side, simply sees the HTML that is produced by the
server and delivered to the web browser.
Where can I get info on using javascript with asp.net textbox fields?
Javascript just see the INPUT field. You'd get the info from the INPUT field
via javascript and the DOM.

Typically you'd use something like getElementByID('IDofYourInputField).value

-Darrel
Jun 27 '08 #3
"darrel" <no*****@nowhere.comwrote in message
news:uz****************@TK2MSFTNGP02.phx.gbl...
Typically you'd use something like
getElementByID('IDofYourInputField).value
Typically, this won't work because chances are you'll have no way of knowing
what the name of the DOM element is by the time it's been rendered to the
client browser - see my earlier reply...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #4
Typically, this won't work because chances are you'll have no way of
knowing what the name of the DOM element is by the time it's been rendered
to the client browser - see my earlier reply...
I've found that it's usually the ID of the usercontrol/webcontrol

However, to be accurate, you use the asp.net clientID propert to write the
value into the javascript:

document.getElementByID('<%=yourInputField.ClientI D%>').value

(which, I just now see, you already mentioned in your other reply. ;o)

-Darrel
Jun 27 '08 #5

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

Similar topics

1
by: cbell | last post by:
I would like javascript file (which can be a .js file) which I can use to play .wav files on demand. there are many pages and there will only be ONE .wav file (about 20 seconds) for each page. ...
5
by: Joey G | last post by:
How do I get the name or identify the control that caused the page postback. I need the information during page init. Reason why, because I need to tell usercontrol_1 that usercontrol_2 button was...
6
by: Brian Miller | last post by:
I've been constructing an ASP.Net application using the 1.1 framework, and have been using Web Matrix for development purposes. Now that my application is near completion, I wanted to see if I can...
3
by: John | last post by:
I am not sure if it is the right forum for Regex topic. If not, please point me the right forum. For a given HTML, I need to identify each asp.net server control. I am not an expert in regex, can...
17
by: B. Chernick | last post by:
I'm trying to create a web page and I need a javascript function to be called on the load of a particular panel. (The panel is hidden during some but not all postbacks.) The function is bound...
4
by: Greg | last post by:
I'm guessing the problem I'm having has something to do with Master Pages or DetailsView because the exact same code works fine on a page without a Master Page and DetailsView controls. The...
5
by: Robert W. | last post by:
I just added this line of code to a simple aspx page: HttpBrowserCapabilities browserCap = new HttpBrowserCapabilities(); Yet when I used QuickWatch in Debug mode to inspect 'browserCap' all...
7
by: HI-Liter | last post by:
On the web page http://news.yahoo.com if you go down the page to "Top Stories", "Most Popular", or any of the other categories, and hover over the links to various articles in any of these...
13
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.