c# - "Object expected" error while calling javascript function -


i want change visibility of textbox, according value selected in dropdownlist.

i have created function this:

function showgiftcardsource() {         var ddlgiftcardsource = document.getelementbyid('<%=ddlgiftcardsource.clientid%>');         var txtgiftcardsource = document.getelementbyid('<%=txtgiftcardsource.clientid%>');          if (ddlgiftcardsource.value == "other") {             txtgiftcardsource.style.visibility = "visible";             txtgiftcardsource.focus();         }     } 

in cs page:

ddlgiftcardsource.attributes.add("onchange", "onselectedindexchanged();");  

and in control:

<asp:dropdownlist id="ddlgiftcardsource" runat="server" width="151px" onchange="showgiftcardsource();"> 

but i'm getting following error:

microsoft jscript runtime error: object expected 

could 1 please me resolve it?

change code behind to:

ddlgiftcardsource.attributes.add("onchange", "showgiftcardsource();"); 

and remove onchange tag:

<asp:dropdownlist id="ddlgiftcardoccasion" runat="server" width="151px"> 

the onchange in tag server side method call.

edit: in case have server side method must first add autopostback drop down in server side onchange event show textbox:

<asp:dropdownlist id="ddlgiftcardoccasion" runat="server" width="151px" onchange="showgiftcardsource" autopostback="true"> 

and in c# code behind:

void showgiftcardsource(object sender, eventargs e) {   //code.....   txtgiftcardsource.visible = true; } 

and of course, rid of ddlgiftcardsource.attributes.add line.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -