Click here to Skip to main content
15,943,210 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having issue while passing the client id value of control getting changed in JavaScript. I am getting exception while passing the value of a dropdown (ctl00_cphDDS_drdInstructionCode) as updated below.
In one server it is rendering as ctl00_cphDDS_drdInstructionCode but in another server it is rendering as cphDDS_drdInstructionCode. Application is running in with 4.6.2 framework. I want to resolve this issue globally. Sample code is updated below.

What I have tried:

Code is as below:
var DropdownList = document.getElementById("ctl00_cphDDS_drdInstructionCode");
var SelectedIndex = DropdownList.selectedIndex;
var SelectedValue = DropdownList.options[DropdownList.selectedIndex].value;
var txtComments = document.getElementById("ctl00_cphDDS_txtUserComments").value;
Updated 25-Jan-24 3:28am

1 solution

You can use the ClientIDMode="Static" attribute on the control (DropDownList), which ensures that the client ID remains the same as the server ID.
<asp:DropDownList runat="server" ID="drdInstructionCode" ClientIDMode="Static">
    <!-- Your rest of code -->
This approach should help you avoid issues related to varying client IDs in different server environments. Also see the link to explore this feature
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900