Why must we add Javascript function from code behind only at the Page_load function
- public partial class WebForm5 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
-
- TextBox1.Attributes.Add("onkeydown", "javascript:alert('keydown')");
-
- }
-
- protected void TextBox1_TextChanged(object sender, EventArgs e)
- {
-
- TextBox1.Attributes.Add("OnKeyDown", "alert('Hello')");
-
- }
- }
The first example added to the Page_Load() works whereas the second one does not