Does anyone know why ASP.NET code behind cannot retrieve the selected value?
After investigating, I discovered that the issue lies within the JavaScript function;
Specifically in the set attribute section:
process.options[process.selectedIndex].setAttribute("style", "color:red;font-weight:600;");
process.options[process.selectedIndex].setAttribute("disabled", "disabled");
If I remove these setAttribute lines, ASP.NET code behind can successfully obtain the selected value.
Are there any solutions available if I still want to utilize the setAttribute component?
Example:
HTML
<html>
<table style="margin-left: auto; text-align: center; margin-right: auto; font-size: large; width: 50%" border="1">
<tr>
<td class="auto-style1">Process Name</td>
<td class="auto-style2">:</td>
<td class="auto-style3">
<asp:DropDownList ID="ddl_processname" runat="server" CssClass="ddl-style" onchange="focustester()">
<asp:ListItem Value="P1">Process 1</asp:ListItem>
<asp:ListItem Value="P2">Process 2</asp:ListItem>
<asp:ListItem Value="P3">Process 3</asp:ListItem></asp:DropDownList>
<br />
<br />
<asp:Label ID="lbl_statio" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style1">Tester Name</td>
<td class="auto-style2">:</td>
<td class="auto-style3">
<asp:TextBox ID="txt_testername" runat="server" AutoPostBack="true" OnTextChanged="TextBox_TextChanged" CssClass="txt-style"></asp:TextBox>
</td>
</tr>
</table>
</div>
<script>
function focustester() {
var process = document.getElementById('<%= ddl_processname.ClientID%>');
if (process.value != "") {
process.options[process.selectedIndex].setAttribute("style", "color:red;font-weight:600;");
process.options[process.selectedIndex].setAttribute("disabled", "disabled");
document.getElementById('<%= txt_testername.ClientID%>').focus();
}
}
</script>
</html>
ASP.NET Code Behind
protected void TextBox_TextChanged(object sender, EventArgs e)
{
TextBox txt_ID = (TextBox)sender;
string get_certain_box = "";
// rest of the code omitted for brevity
}