473,770 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing Web Forms Controls with javascript

Red
Can you access web form control via javascript ie..

if I have <asp:textbox runat=server id=txtTextbox/>

can I say in javascript

txtTextbox.Enab led = true;

??
Nov 18 '05 #1
2 1776
Personally, I could never get you using the ID attribute of a Web control to work with JavaScript. Instead, when you view the source of your web page from a Web browser you will see that the server automatically assigns the Web control a ClientID the usually begins, at least in my experience, something line "_ctl0_<ID attribute value>". Since the Enabled property is server side I'm not sure that you would be able to control it like that using JavaScript. However, a workaround could be to set the display attribute of the controls style property to 'block' if you wanted it to be visible and 'none' if you wanted it to be not visible. A sample JavaScript code would be

function ShowControl (controlID)
var element = document.getEle mentById (controlID)
//to show the element use the followin
element.style.d isplay = 'block'
//to hide the element use the followin
element.style.d isplay = 'none'
However, the above function works well in Internet Explorer, but the earlier versions of Opera does not support the display property, so you would have to use the visibility attribute instead as follows

function ShowControl (controlID)
var element = document.getEle mentById (controlID)
//to show the element use the followin
element.style.v isibility = 'visible'
//to hide the element use the followin
element.style.v isibility = 'hidden '
I hope this helps
Ji

Nov 18 '05 #2
Red
That was what I was looking for. Thanks alot.
"Jim Mace" <an*******@disc ussions.microso ft.com> wrote in message
news:59******** *************** ***********@mic rosoft.com...
Personally, I could never get you using the ID attribute of a Web control to work with JavaScript. Instead, when you view the source of your web page
from a Web browser you will see that the server automatically assigns the
Web control a ClientID the usually begins, at least in my experience,
something line "_ctl0_<ID attribute value>". Since the Enabled property is
server side I'm not sure that you would be able to control it like that
using JavaScript. However, a workaround could be to set the display
attribute of the controls style property to 'block' if you wanted it to be
visible and 'none' if you wanted it to be not visible. A sample JavaScript
code would be:
function ShowControl (controlID) {
var element = document.getEle mentById (controlID);
//to show the element use the following
element.style.d isplay = 'block';
//to hide the element use the following
element.style.d isplay = 'none';
}

However, the above function works well in Internet Explorer, but the earlier versions of Opera does not support the display property, so you
would have to use the visibility attribute instead as follows:
function ShowControl (controlID) {
var element = document.getEle mentById (controlID);
//to show the element use the following
element.style.v isibility = 'visible';
//to hide the element use the following
element.style.v isibility = 'hidden ';
}

I hope this helps,
Jim

Nov 18 '05 #3

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

Similar topics

6
2746
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is called "form1", and I have selects called "PORTA", "PORTB" ... etc...
4
12107
by: Jim Heavey | last post by:
Hello, I have created a form which I intend to use a a dialog box. It has a few controls on that form and I changed the properties of those controls to "public" with the idea that I could access those controls from the "calling form", but I am unable to access/see those controls. Why? Here are portions of my code Here I am substantiating the new form and trying to set values for the controls on that form...
2
1399
by: Bluelace | last post by:
I have a screen which has as number of textboxes on a screen which I wish to initialise using a loop. The textboxes are named textBox1, textBox2 etc. I hoped I hoped that I could address the component as I could in Java, VB6 or JavaScript in the folllowing manner : for (int x = 1; x < max;x++) { Form1.("textBox" + x.ToString()).Text = getDetails(x); }
1
3139
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such as: 1)
5
1947
by: RSH | last post by:
I havent been able to set a property from another class with out getting some sort of error. Can someone please tell me what I'm doing wrong here? Public Class Form1
7
1924
by: Sudhakara.T.P. | last post by:
Hi, I have an tab control in one of the forms and it has two tab strips. Now I have written an general function that accepts form name as parameter and iterates through all the controls in the form and re-initialises that. Now in this context, i have around 15 controls on one of the tab strips page 1 and 5 controls in tab strip 2. now when i iterate through the controls, i am getting the control collection as 3 as there are two more...
4
3640
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if possible.. for example..i hav a menu in the parent form named "Administrator" whic has an item "mnuLogIn"..now when i click on login..another child form named "frmLogIn" is displayed..what i want to happen is this: when login form(frmLogIn) is...
3
10521
by: judy.j.miller | last post by:
Does anyone know why i can't access a form element value using dot notation in firefox, when i'm in a function. Works ok in the body. I'm trying to do this: var FarTemp = faren.temp.value; I can get at the value using the array method, the getelements by id method, and the bracket-with-the-element-name in it method. But the dot notation doesn't work, in firefox, in the function (which i have in the head).
8
2183
by: colmkav | last post by:
Hi, could someone tell me how I can check whether a database is open by name eg something like db("mydbname")
0
9619
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
10260
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...
0
10102
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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
8933
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
7460
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...
1
4007
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
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.