I’ve got some trouble with jQuery script on my Asp.net page. During first load it works well, after postback it does not. Initially I thought that it is because script is not load again, but alert told me that script runs as I use function pageLoad() instead of $(document).ready(function(). In script I just read value from one text area and set the length value to next text input. I am putting script into page like this:
<script type='text/javascript' src='../js/smsanywhere.js'></script>
I tried to place directly into page, but there is no difference I guess.
The script is shown below.
function pageLoad() { alert('pageLoad is there'); var textBox = 'textarea[id*='txtMessage']'; var counterBox = 'input[id*='txtCharLeft']'; $(textBox).keydown(function(){ alert(this); var length = 70 - $(this).val().length; $(counterBox).val(length); $(counterBox).attr('style',function(){ return 'width:30px;' + (length < 0 ? 'background-color:Red;' : ''); }); }); }
I don’t use any ajax at this page, its just master page , content page and jQuery.
What am I missing?
I found the problem….as I add reference to jquery like this:
But I placed inside if (!IsPostBack){ … } so I was ….solution is only to remove it from this condition and run it each time…uff.
So mystery sorted out…