开发者

dropdown value changed by javascript is not coming in codebehind

I have a dropdown list whose value is changed based on other controls in the UI using javascript.

I used the following code to change the dropdown list, document.getElementById("ddlchkStsID").options[2].selected 开发者_开发知识库= true; document.getElementById("ddlchkStsID").value = "3";

But in the code-behind, the ddlchkStsID.SelectedValue is still coming as first option's value.

This the control in aspx page.

<asp:DropDownList ID="ddlchkStsID"  runat="server" TabIndex="10"  CssClass="meta">
 <asp:ListItem Text="TBD" Value="1" />
 <asp:ListItem Text="Yes" Value="2" />
 <asp:ListItem Text="No" Value="3" />
</asp:DropDownList>

Could someone help me how to get the changed value in the code-behind.

thanks in advance :)


Since the control is running at the server, you should be referencing the control using the ClientID, like this:

document.getElementById("<%=ddlchkStsID.ClientID%>").options[2].selected = true;

Is your JavaScript code actually working?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜