JavaScript in Web User Control
-
Hi!! I am using Javascript in user control.. My problem is i am not getting the value of textbox in javascript. here is my code function InputChange() { var ctl=document.getElementById('txtEmp').value; alert(ctl); } <asp:TextBox ID="txtEmp" onchange="InputChange();" runat="server" CssClass="form_textbox" Width ="80px"></asp:TextBox> its displaying 'ctl' value as 'null' please help me ASAP... Thanks in Advance...
-
Hi!! I am using Javascript in user control.. My problem is i am not getting the value of textbox in javascript. here is my code function InputChange() { var ctl=document.getElementById('txtEmp').value; alert(ctl); } <asp:TextBox ID="txtEmp" onchange="InputChange();" runat="server" CssClass="form_textbox" Width ="80px"></asp:TextBox> its displaying 'ctl' value as 'null' please help me ASAP... Thanks in Advance...
Its because when you are using User Control or anything ASP genrate a unique client id to every control you are giving wrong i Id i guess unction InputChange() { var ctl=document.getElementById("<%=txtEmp.ClientID %>").value; alert(ctl); }
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
modified on Tuesday, April 22, 2008 3:41 AM
-
Hi!! I am using Javascript in user control.. My problem is i am not getting the value of textbox in javascript. here is my code function InputChange() { var ctl=document.getElementById('txtEmp').value; alert(ctl); } <asp:TextBox ID="txtEmp" onchange="InputChange();" runat="server" CssClass="form_textbox" Width ="80px"></asp:TextBox> its displaying 'ctl' value as 'null' please help me ASAP... Thanks in Advance...
Most likely the id of the control on the emitted page is actually something like: ctl00_master_txtEmp or similar. Look at the source to find this: it is named after the parent element (such as the ContentPlaceHolderID). As an example right click this page, click view source and you will see many examples of this. Your code would then be:
var ctl=document.getElementById('ctl00_master_txtEmp').value; alert(ctl);
-
Hi!! I am using Javascript in user control.. My problem is i am not getting the value of textbox in javascript. here is my code function InputChange() { var ctl=document.getElementById('txtEmp').value; alert(ctl); } <asp:TextBox ID="txtEmp" onchange="InputChange();" runat="server" CssClass="form_textbox" Width ="80px"></asp:TextBox> its displaying 'ctl' value as 'null' please help me ASAP... Thanks in Advance...
Its better to give a client id dynamic instead of static Check my above modified code that will work
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Its because when you are using User Control or anything ASP genrate a unique client id to every control you are giving wrong i Id i guess unction InputChange() { var ctl=document.getElementById("<%=txtEmp.ClientID %>").value; alert(ctl); }
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
modified on Tuesday, April 22, 2008 3:41 AM