HI,
Why must we add Javascript function from code behind only at the Page_load function The first example added to the Page_Load() works whereas the second one does not
- public partial class WebForm5 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- //this works
- TextBox1.Attributes.Add("onkeydown", "javascript:alert('keydown')");
- //TextBox1.Attributes.Add("onchange", "javascript:alert('change')");
- }
- protected void TextBox1_TextChanged(object sender, EventArgs e)
- {
- //this does not
- TextBox1.Attributes.Add("OnKeyDown", "alert('Hello')");
- //TextBox1.Attributes.Add("onkeydown", "javascript:alert(this);");
- }
- }
Jignesh KumarPosted Feb 4, 2019, 2:21 AM
Salman BegPosted Feb 4, 2019, 1:28 AM
Cally KPosted Feb 4, 2019, 1:21 AM
Jignesh KumarPosted Feb 4, 2019, 12:56 AM
Cally KPosted Feb 4, 2019, 12:43 AM
Jignesh KumarPosted Feb 4, 2019, 12:34 AM
Salman BegPosted Feb 4, 2019, 12:30 AM