javascript - Using Jquery in UserControl with MasterPage -
i can't seem javascript work on usercontrol. want count characters in mulitline textbox (which adds level of complexity). want count characters , display them in label.
i have javascript in .js file included in masterpage:
function textcounter(field, countfield, maxlimit) { var output = document.getelementbyid(countfield); if (output == null) { return; } if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit); else output.value = maxlimit - field.value.length; }
my usercontrol has little code:
<script type="text/javascript" language="javascript"> if (typeof contentpageload == 'function') { var outputfield = $("[id$='lblcharactercount']"); } </script> <asp:textbox id="txtmytest" runat="server" height="75px" cssclass="form-field full" textmode="multiline" maxlength="140" onkeyup="textcounter(this, outputfield, 140);" onkeydown="textcounter(this, outputfield, 140);" ></asp:textbox> <asp:label id="lblcharactercount" runat="server"></asp:label>
outputfield null when tries execute function. i've tried adding it(the script on usercontrol) in scriptblock in usercontrol pageload, prerender , preinit. nothing seems work.
update:
i able usercontrol javascript working w/o updatepanel. problem, usercontrol in updatepanel. i've given on using usercontrol in updatepanel js unless can offer advice.
try changing selector this:
var outputfield = $("#<% lblcharactercount.clientid %>");
the id set on control not id gets assigned in html generated. using clientid property, html id.
of course haven't used asp.net in while answer might worthless.
Comments
Post a Comment