0

I have created one page.In that page,I wrote one javascript function for displaying character count,when user enter something in textbox.

protected void Page_Load(Object sender, EventArgs e)
{ 
    TextBox1.Attributes.Add("onkeyup", "DisplayCharCount()");
}

First time pageload,textbox is blank. Textbox does not have autopostback== true.After pageload,user enter text into textbox.This time page is not loaded again.So when this function get called?

1
  • why cant you call this script in markup? Commented Jun 20, 2013 at 6:44

2 Answers 2

1

Page_Load will call everytime a page reloaded. so onkeyup will bind to the textbox everytime a page reloaded.

When this function get called?

This event is triggered when the user releases a Key while typing on TextBox1.

You can also bind it for the first time only:

protected void Page_Load(Object sender, EventArgs e)
{ 
    if(!IsPostBack)
    {
        TextBox1.Attributes.Add("onkeyup", "DisplayCharCount()");
    }
}

Or you can also bind it directly as:

<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" onkeyup="DisplayCharCount()">
</asp:TextBox>
Sign up to request clarification or add additional context in comments.

Comments

0

The Page_Load method is called every time a user requests the page. The DisplayCharCount method is called whenever a user pressed a key (that is, release the key) in the TextBox1 element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.