Note that there are some explanatory texts on larger screens.

plurals
  1. POEvent handler doesn't call the cellclick method
    primarykey
    data
    text
    <p>I've implemented the clickable table cell using a extended class. However, when I call the event handler/onclick method in my main class, the event handler doesn't work.</p> <p>Extended clickable table cell class:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Member { public class TableCellClick: TableCell, IPostBackEventHandler, INamingContainer { private static readonly object click_event = new object(); // public handles for adding and removing functions to be called on the click event public event EventHandler Click { add { Events.AddHandler(click_event, value); } remove { Events.RemoveHandler(click_event, value); } } // define parent function that will be called when the container is clicked protected void OnClick(EventArgs e) { EventHandler h = Events[click_event] as EventHandler; if (h != null) { h(this, e); } } // specify the "post back event reference" or id of the click event protected override void AddAttributesToRender(HtmlTextWriter writer) { base.AddAttributesToRender(writer); writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(this, "custom_click")); } // link the custom click id to the click function void System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(string eventArgument) { if(eventArgument == "custom_click") { OnClick(EventArgs.Empty); } } } } </code></pre> <p>The method in my Main class:</p> <pre><code> memPanel.Visible = true; //Set a table width. memTable.Width = Unit.Percentage(40.00); //Create a new row for adding a table heading. TableRow tableHeading = new TableRow(); //Create and add the cells that contain the msno column heading text. TableHeaderCell msnoHeading = new TableHeaderCell(); msnoHeading.Text = "M'Ship No."; msnoHeading.HorizontalAlign = HorizontalAlign.Left; tableHeading.Cells.Add(msnoHeading); //Create and add the cells that contain the Name column heading text. TableHeaderCell nameHeading = new TableHeaderCell(); nameHeading.Text = "Name"; nameHeading.HorizontalAlign = HorizontalAlign.Left; tableHeading.Cells.Add(nameHeading); memTable.Rows.Add(tableHeading); while (reader.Read()) { TableRow detailsRow = new TableRow(); TableCellClick msnoCell = new TableCellClick(); msnoCell.Text = reader["MSNo"].ToString(); msnoCell.Click += cellClick; detailsRow.Cells.Add(msnoCell); TableCellClick nameCell = new TableCellClick(); nameCell.Text = reader["fName"].ToString(); nameCell.Click += cellClick; memTable.Rows.Add(detailsRow); } </code></pre> <p>The onclick method: </p> <pre><code>protected void cellClick(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("cell click"); memPanel.Visible = false; basicInfo.Visible = true; } </code></pre> <p>Anyone knows where it went wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload