Click here to Skip to main content
13,863,229 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi,

I am a beginner in web development especially in client side scripting. I get an exception

"0x800a1391 - JavaScript runtime error: 'cmbThemes' is undefined"

in the below code.

Please help me fix this.

function(s, e){
if(cmbThemes.SelectedText=="Glass"){
alert ('Glass');
}
Posted
Comments
Taha Akhtar 19-Nov-13 6:23am
   
First you should get what is cmbThemes?


use
debugger; in your console window of browser for debugging.
Rahul Krishnan R 19-Nov-13 6:58am
   
cmbThemes is the id of the combo box
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

function(s, e){
var cmbThemes=document.getElementById('cmbThemes')

if(cmbThemes.options[cmbThemes.selectedIndex].text=="Glass"){
alert ('Glass');
}


You can also use jquery for it

$("#cmbThemes option:selected").text();
   
v4
Comments
Rahul Krishnan R 20-Nov-13 0:05am
   
I get the below error when I tried the code:

"0x800a138f - JavaScript runtime error: Unable to get property 'options' of undefined or null reference"
Rahul Krishnan R 26-Nov-13 1:53am
   
Hi,
I am using devexpress webcontrols and jquery not seem to work in those controls
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I couldn't get the above code to work. Even I tried with some other scenarios with button control like below

function(s, e) {
var lblSignin=document.getElementById('lblSignin');
lblSignin.style.backgroundColor = "#FF6600";
}


Here I want to change the background color of the label lblSignin on a button click event. But I end up with below error on click event:

" 0x800a138f - JavaScript runtime error: Unable to get property 'style' of undefined or null reference "

Please help me fix this issue....!!!!

FYI I am using DevExpress controls.



Thanks in advancex
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Hi,

Changed ClientIDMode property to Static and got the solution solved.

Got this from ASP.net forum

ASP.NET provides multiple algorithms for how to generate the ClientID property value. You select which algorithm to use for a control by setting its ClientIDMode property. The algorithms are identified by the ClientIDMode enumeration values that are listed in the following table.

<div class="caption"></div> <div class="tableSection">
Value

Description

AutoID

The ClientID value is generated by concatenating the ID values of each parent naming container with the ID value of the control. In data-binding scenarios where multiple instances of a control are rendered, an incrementing value is inserted in front of the control's ID value. Each segment is separated by an underscore character (_). This algorithm was used in versions of ASP.NET earlier than ASP.NET 4.

Static

The ClientID value is set to the value of the ID property. If the control is a naming container, the control is used as the top of the hierarchy of naming containers for any controls that it contains.

Predictable

This algorithm is used for controls that are in data-bound controls. The ClientID value is generated by concatenating the ClientID value of the parent naming container with the ID value of the control. If the control is a data-bound control that generates multiple rows, the value of the data field specified in the ClientIDRowSuffix property is added at the end. For the GridView control, multiple data fields can be specified. If the ClientIDRowSuffix property is blank, a sequential number is added at the end instead of a data-field value. Each segment is separated by an underscore character (_).

Inherit

The control inherits the ClientIDMode setting of its NamingContainer control.

</div>
The default value of ClientIDMode for a page is Predictable. The default value of ClientIDMode for a control is Inherit. Because the default for controls is Inherit, the default generation mode is Predictable. (However, if you use Visual Studio to convert a Web project to ASP.NET 4 from an earlier version, Visual Studio automatically sets the site default to AutoID in the Web.config file.)
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190214.1 | Last Updated 26 Nov 2013
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100