I have a page where I dynamically create a radcombox, a radnumerictextbox with percent type and a radnumerictextbox with currency type. Depending on the item selected, I would hide one and display the other.
-- code behind
if (cboCommType.SelectedValue == "1")
{
txtOngoingPer.Style.Add("display", "inline");
txtOngoingCurrency.Style.Add("display", "none");
}
else if (cboCommType.SelectedValue != "4")
{
txtOngoingPer.Style.Add("display", "none");
txtOngoingCurrency.Style.Add("display", "inline");
}
--client side code
function cboCommType_OnClientSelectedIndexChanged(sender, eventArgs, ctlId) {
var item = eventArgs.get_item();
var selectedValue = item.get_value();
var txtID = sender.get_id();
$('#' + txtID.replace('cboCommType', 'hdnCommType')).val(item.get_value());
var txtFee = document.getElementById("ctl00_FormContentPlaceHolder_txtFee_" + ctlId);
var txtPer = document.getElementById("ctl00_FormContentPlaceHolder_txtOngoingPer_" + ctlId);
var txtCur = document.getElementById("ctl00_FormContentPlaceHolder_txtOngoingCurrency_" + ctlId);
if (selectedValue == "4") {
txtFee.value="";
txtFee.setAttribute("disabled", "disabled");
if (txtPer != null) {
txtPer.value = '';
txtPer.setAttribute("disabled", "disabled");
}
if (txtCur != null) {
txtCur.value = '';
txtCur.setAttribute("disabled", "disabled");
}
}
else {
txtFee.removeAttribute("disabled");
if (selectedValue == "1") {
if (txtPer != null) {
txtPer.removeAttribute("disabled")
txtPer.setAttribute("style", "height: 24px; display:inline");
txtPer.value = txtCur.value;
txtCur.setAttribute("style", "display:none");
}
}
else {
if (txtCur != null) {
txtCur.removeAttribute("disabled")
txtCur.setAttribute("style", "height: 24px; display:inline");
txtCur.value = txtPer.value;
txtPer.setAttribute("style", "display:none");
}
}
}
}