Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
below is my java script function :

function LimtCharacters(txtMsg, CharLength, indicator) {
chars = txtMsg.value.length;
document.getElementById(indicator).innerHTML = CharLength - chars;
if (chars > CharLength) {
txtMsg.value = txtMsg.value.substring(0, CharLength);
}
}

and its working on the onkeyup event of the text box like below :

ASP.NET
<asp:TextBox runat="server" ID="TxtSms" Width="245px" TextMode="MultiLine" Height="57px"
                        placeholder="Max 160 Characters" BackColor="LightGray" onkeyup="LimtCharacters(this,160,'lblcount');"
                        TabIndex="1">
                    </asp:TextBox>
                    <label id="lblcount" style="color: Red;" runat="server">&nbsp; 160</label>



now i want to use this on page load and i am using master child concept.

so any help would be appreciated and its urgent if any one have idea with example.

thanks in advance.
Posted
Updated 11-Dec-15 18:23pm
v2

1 solution

This action has nothing to do with ASP.NET. Perhaps the simplest way would be this:
HTML
<html>
   <head>
      <title>Do something on load</title>
   </head>
<body>


<script>

document.body.onload = function() {

   DoSomethingHere();

}

</script>

</body>
</html>

Remaining problem is the function you show in your question. I have no idea why would you do such weird thing and how can you use a hard-coded constant 160. But it's apparent that to call it on load, you cannot use "this"; you should, again, take the DOM element related to your text box by ID and pass it instead of "this".

—SA
 
Share this answer
 
Comments
ketan chandpa 12-Dec-15 2:11am    
thanks for comment sir but please can u post the right solution with example if possible because i passed the ID of the text box instead of hard code but it is not working and also how to pass parameters in the java script function on page load and also i want to call the java script function on page load in content page also.
Sergey Alexandrovich Kryukov 12-Dec-15 2:58am    
No, first, please show your new code, even if it's "not working". I think I explained your everything, except one thing I don't understand: what you want to achieve.
By the way, there is no such thing as "java script"; Java is not a scripting language. ;-)
—SA
ketan chandpa 12-Dec-15 3:33am    
sorry but you really not get what i want to achieve.....? too strange. i ask just simple question that how to call a javascript function which has parameters in the page load just it. what you not understand in this question?
Sergey Alexandrovich Kryukov 12-Dec-15 3:37am    
That part of the question I understood, but I fully answered it. What you don't understand in my answer? :-)

As to my question, basically, I don't understand the role of 160. What do you want to achieve with that? But if I could ignore this, assuming that you really have what you want, I answered already.

—SA
ketan chandpa 12-Dec-15 3:47am    
thanks for comment but the 160 is the character limit given to the textbox and when i call this javascript function onkeyup event of the textbox then it is working well but don't know how to achieve this on page load of the content page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900