I have a dynamic button which is being rendered through an ASP:Literal
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter writer = new HtmlTextWriter(sw);
Button btnOpenFile = new Button();
btnOpenFile.ID = "BtnOpenFile-" + additionalReadingFileID;
btnOpenFile.Text = "Open";
btnOpenFile.CssClass = "SettingsChangeButton";
btnOpenFile.Click += new EventHandler(OpenFileInLocation);
btnOpenFile.RenderControl(writer);
writer.Close();
sw.Close();
this.LitAdditionalReadingContent.Text = sb.ToString();
The methods being added to the click event is
protected void OpenFileInLocation(object sender, EventArgs e)
{
// Change Selected ID to this one
Button clickedLink = (Button)sender;
int fileID = Convert.ToInt32(clickedLink.ID.Replace("BtnOpenFile", ""));
IRPBestPracticeTopicAdditionalReadingFile myOpenFile = new IRPBestPracticeTopicAdditionalReadingFile(fileID);
System.Diagnostics.Process.Start(@myOpenFile.FilePath);
}
This works when i add a button on the ASP page and assign the click event to the button on the page load method, but doesnt seem to register when i am assigning it to a dynamically created button being rendered via a literal.
Does anyone know why? And is there a simple solution to this problem? Thanks in advance.