Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / January 2005

Tip: Looking for answers? Try searching our database.

Referencing a Web Form Control in JavaScript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Plato - 31 Oct 2003 04:51 GMT
I have a form containing several dropdown list boxes (web form controls
<asp:dropdownlist> ) not the html <select> type control and I need to
reference the list box in a javascript function.

A snippet of code follows:

function DisplaySBDocList(searchType) {
   // There are three methods of searching the database
   // 1. Manufacturer
   // 2. Model
   // 3. Keyword
   //
   // Depending on the search type get the appropriate search string

   var form = document.forms[0]
   var comboIndex
   var searchString

   //var fieldValue = field.value

   try
   {
       if (searchType == "1")
       {
           comboIndex = form.cmbManufacturer.selectedIndex;
           searchString = form.cmbManufacturer.options(comboIndex).text;
       }

        if (searchType == "2")
       {
           comboIndex = form.cmbModel.selectedIndex;
           searchString = form.cmbModel.options(comboIndex).text;
       }

When I try to access web form controls the same way as a HTML controls  I
get an error:

cmbManufacturer.selectedIndex is null or is not an object

If you look at the page code from "View Source" on the popup menu the Name
and ID properties of the web form control are now:

Name="_ctl6:cmbManufacturer"
ID="_ctl6_cmbManufacturer"

So the question is; how do you reference ASPNET controls in JavaScript?

Perplexed

Andrew
MSFT - 31 Oct 2003 09:54 GMT
Hi Andrew,

Is "cmbManufacturer" in a datagrid or repeater? Normamlly, ASP.NET control
will have same ID on server side and client side. However, when it is added
to datagird, repeater or datalist, there will be multiple instance of it.
ASP.NET will add prefix like "ctl6" to their ID property, to distinguish
them. To access them on client with Javascript, you may compose a string
like: "MyDataGrid__ctl3_cmbManufacturer" with row number, and use
document.all("MyDataGrid__ctl3_cmbManufacturer").

Luke
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Plato - 03 Nov 2003 05:05 GMT
Hi Luke,

It is actually a combobox in a table, not a datagrid or a combobox within a
datagrid.

It is a lookup form I have created which I am using in the ASPNET Portal
starter kit.

Its purpose is to search a table in SQL2000 for attributes of machine
service bulletins. There are two combo boxes:
1. Manufacturer - displays a list of all manufacturers of products we
distribute and an adjacent Go button.
2. Models of machines made by the manufacturer. This combo is populated when
a manufacturer is selected in the 1st combobox, and an adjacent Go button.
There is also a textbox used for keyword search, and an adjacent Go button.

How it works:
The user can select a manufacturer from the 1st combobox, this will populate
the second combobox with models of machines manufactured by the selected
manufacturer. The user can either click the Go button alongside the
Manufacturer combobox and display a list of all parts and service bulletins
applicable to the selected manufacturer:
OR
the use selects a machine model from the second combobox then clicks the Go
button which will display a list of all parts and service bulletins
appicable to the machine model selected:
OR
the user can type in a key word or phrase, click the Go button and a list of
all parts and service bulletins containing the keyword(s) or phrase will be
displayed.

I am using the onclick event of the button to fire a javascript function to
display the appropriate data in a new window.

> Hi Andrew,
>
[quoted text clipped - 12 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
MSFT - 05 Nov 2003 05:06 GMT
From your reply, I realized that your application is not a normall ASP.NET
application, but an ASP.NET app on mobile device. You mentioned you are
work with " ASPNET Portal starter kit". The only support for the ASP.Net
portal kit is through the forums at www.asp.net. You may post your question
there to see if you get more help.

Thanks,

Luke
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

hem meh - 31 Jan 2005 13:20 GMT
hi Luke,

pl. help me futhere to use javascript with datagrid. In my application i am have check box control in first colum. When i click on any check box i want to change the color of that row of the grid. so pl. help me.

thankx in advance.

Hemal

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.