First of all I have seen lots of questions and answers about this situation with JavaScript functions from the page header. I am working with C# and have my event handler defined in the CodeBehind file.
Here is the code that creates my button:
Button btnDelete = new Button()
{
ID = "btnLeadershipRowDelete" + index.ToString(),
Text = "-"
};
btnDelete.OnClientClick = "BtnDeleteRow_Click";
btnDelete.Attributes.Add("style", "display: inline-block; width: 1.4em;");
pnlLeadershipControls.Controls.Add(btnDelete);
Here is the HTML rendered for the same button:
<input type="submit" name="ctl00$ctl00$cphContent$cphContent1$btnLeadershipRowDelete0" value="-"
onclick="BtnDeleteRow_Click;" id="ctl00_ctl00_cphContent_cphContent1_btnLeadershipRowDelete0"
style="display: inline-block; width: 1.4em;" />
Here is the event handler method I am trying to call:
protected void BtnDeleteRow_Click(object sender, EventArgs e)
{
DeleteControls(sender);
}
When I click the button in Chrome, nothing happens. Looking at the dev console in Chrome, I find the following error:
default.aspx:1 Uncaught ReferenceError: BtnDeleteRow_Click is not defined at HTMLInputElement.onclick (default.aspx:1)
I am at a loss as to what I have done wrong. Any thoughts will be helpful!