Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have created a custom control that inherits from the Panel control. I did this to add a click event to it. The custom control is contained inside a ListView so I am trying to add a property that I can bind data to and retrieve on the click event.

Here is the markup:

ASP.NET
<asp:ListView ID="lstvwCalendar" runat="server" OnLayoutCreated="lstvwCalendar_LayoutCreated">
     <layouttemplate>
                    <table>
                        <tr class="day_of_week">
                            <th>
                                Name
                            </th>
                        </tr>
                        <asp:PlaceHolder ID="itemPlaceHolder" runat="server">
                    </table>
                </layouttemplate>
                <itemtemplate>
                    <tr class="day_of_week">
                        <td>
                            <cc1:clickablepanel id="pnlSunday"  runat="server"  önclick="ClickablePanel1_Click"
                                width="100%" height="100%" CommandArgument='<%# Eval("Name") %>'>
                            
                        </td>
                    </tr>
                </itemtemplate>


The problem is that the CommandArgument property is always null.

Here is the code for the custom control:

C#
public class ClickablePanel : System.Web.UI.WebControls.Panel, System.Web.UI.IPostBackEventHandler
    {
        [System.ComponentModel.Bindable(true)]
        public string CommandArgument { get; set; }
        public ClickablePanel() : base()
        {
            
        }
        private event EventHandler _click;
        public event EventHandler Click
        {
            add { _click += value; }
            remove { _click -= value; }
        }
        
        protected virtual void FireClickEvent()
        {
            if (_click != null)
            {
                _click(this, new EventArgs());
            }
        }
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(this, String.Empty));
            base.AddAttributesToRender(writer);
        }
        public void RaisePostBackEvent(string eventArgument)
        {
            FireClickEvent();
        }
        public event System.ComponentModel.PropertyChangedEventHandler CommandArgumentChanged;
        public void OnCommandArgumentChanged(System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (CommandArgument != null)
            {
                CommandArgumentChanged(this, e);
            }
        }
    }


Any help would be great. Thanks.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900