Disable DropDownList at ClientSide
-
Hi All, Please advise how to enable/disable DropDownList at ClientSide. I have the following function, it does work for textbox and button but not on dropdownlist.
function Disable() {
var chk = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox).ClientID %>') var btn = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("btnAdd"), Button).ClientID %>') var ddl = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddList"), DropDownList).ClientID %>') var txt = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtName"), textbox).ClientID %>') if (chk.checked == true) { btn.disabled = true; ddl.disabled = true; txt.disabled = true; } else { btn.disabled = false; txt.disabled = false; ddl.disabled = false; } }
Thanks and best regards
-
Hi All, Please advise how to enable/disable DropDownList at ClientSide. I have the following function, it does work for textbox and button but not on dropdownlist.
function Disable() {
var chk = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox).ClientID %>') var btn = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("btnAdd"), Button).ClientID %>') var ddl = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddList"), DropDownList).ClientID %>') var txt = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtName"), textbox).ClientID %>') if (chk.checked == true) { btn.disabled = true; ddl.disabled = true; txt.disabled = true; } else { btn.disabled = false; txt.disabled = false; ddl.disabled = false; } }
Thanks and best regards
It works and it should work for drop down list also. Just check the spelling of the Control's Id and also check and confirm if ddl is not a null.
Anurag Gandhi.
http://www.gandhisoft.com
Life is a computer program and every one is the programmer of his own life.
My latest article: Group GridView Data -
It works and it should work for drop down list also. Just check the spelling of the Control's Id and also check and confirm if ddl is not a null.
Anurag Gandhi.
http://www.gandhisoft.com
Life is a computer program and every one is the programmer of his own life.
My latest article: Group GridView Data -
Hi thanks for the reply I have already checked ddl, it is not null and the value is "[object HTMLSelectElement]". This is my control
Thanks and best regards
As Anurag suggested, please check the Id of the dropdown. Moreover, where you are calling this javascript method
Disable()
from? Just a Note : May be you know this. You can avoid if..else condition by using,btn.disabled = chk.checked ;
txt.disabled = chk.checked ;
ddl.disabled = chk.checked ;Arun Jacob My Technical Blog : Code.NET
-
As Anurag suggested, please check the Id of the dropdown. Moreover, where you are calling this javascript method
Disable()
from? Just a Note : May be you know this. You can avoid if..else condition by using,btn.disabled = chk.checked ;
txt.disabled = chk.checked ;
ddl.disabled = chk.checked ;Arun Jacob My Technical Blog : Code.NET
Thanks :)
Arun Jacob wrote:
please check the Id of the dropdown.
ID is correct and I got ddl(not null), the value is "[object HTMLSelectElement]"
Arun Jacob wrote:
where you are calling this javascript method
Disable()
from?The calling is at Checkbox onClick, I put this code in Page_load event:
Dim chk As CheckBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox)
chk.Attributes.Add("onclick", "Disable()")Thanks and best regards
-
Thanks :)
Arun Jacob wrote:
please check the Id of the dropdown.
ID is correct and I got ddl(not null), the value is "[object HTMLSelectElement]"
Arun Jacob wrote:
where you are calling this javascript method
Disable()
from?The calling is at Checkbox onClick, I put this code in Page_load event:
Dim chk As CheckBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox)
chk.Attributes.Add("onclick", "Disable()")Thanks and best regards
ddl.disabled = true;
is correct and it should work. I hopeAutoPostBack
is false for CheckBox. Alternatively you can try,ddl.disabled = "disabled";
Arun Jacob My Technical Blog : Code.NET
-
ddl.disabled = true;
is correct and it should work. I hopeAutoPostBack
is false for CheckBox. Alternatively you can try,ddl.disabled = "disabled";
Arun Jacob My Technical Blog : Code.NET
-
Arun Jacob wrote:
I hope
AutoPostBack
is false for CheckBox.Sure, AutoPostBack is false.
ddl.disabled = "disabled";
this doesn't work too :(
Okay.Then you can debug the method by using,
debugger;
debug the code and try to explore ddl object so that you can find the issue.
Arun Jacob My Technical Blog : Code.NET
-
Hi All, Please advise how to enable/disable DropDownList at ClientSide. I have the following function, it does work for textbox and button but not on dropdownlist.
function Disable() {
var chk = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox).ClientID %>') var btn = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("btnAdd"), Button).ClientID %>') var ddl = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddList"), DropDownList).ClientID %>') var txt = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtName"), textbox).ClientID %>') if (chk.checked == true) { btn.disabled = true; ddl.disabled = true; txt.disabled = true; } else { btn.disabled = false; txt.disabled = false; ddl.disabled = false; } }
Thanks and best regards
Use Dropdownlistname.visible=false property like in aspx page if(!page.ispostback) { Dropdownlistname.visible=false; }