I've created in my code a linkButton dynamically using this:
LinkButton linkPDFQ = new LinkButton();
linkPDFQ.ID = "linkPDF";
linkPDFQ.CommandArgument = fisrtArg + ";" + secondArg;
linkPDFQ.Text = fisrtArg;
linkPDFQ.Command += new CommandEventHandler(PDFCLink_Action);
row.Cells[0].Controls.Add(linkPDFQ);
where row is coming from a GridViewRow and the CommandEventHandler is this
protected void PDFCLink_Action(object sender, CommandEventArgs e)
{
string[] arg = new string[2];
arg = e.CommandArgument.ToString().Split(';');
string arg1 = arg[1];
string arg2 = arg[2];
Response.Write("<script>alert('" + arg1 + arg2 "'); </script>");
}
only to see if I click on linkButtton then I receive the alert... but nothing!!! The linkButton doesn't work... I have made another linkButton starting from aspx with a similar code and everything goes well because in apsx I can use the method OnCommand that it's not possible to use in aspx.cs. What I miss or where I made an error? How is possible to replace OnCommand in cs file? Thanks
The code below is working fine. I found couple of errors in the code and fixed, Please see the below comments.
Other than above, the CommandEventHandler you implemented is correct. Please let me know if it works.