I'm trying to use the OnClick callback to call a C# function, however javascript throws an error saying the function is undefined (even though it is in the C# code).
This only happens if I add the control via Controls.Add in the page_load of the C# call behind section.
In other words if I do this (in the Page_Load function):
LinkButton l = new LinkButton();
l.Text = "Test";
l.ID = "TestID";
l.Attributes.Add("OnClick", "LinkButton_Click");
l.Attributes.Add("runat", "server");
l.Page = Page;
this.Controls.Add(l);
LinkButton_Click is not defined according to javascript, however if I do this:
In the ascx file it runs fine anda ctually calls the C# function.