+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Button event in DynamicDetailContainer

Button event in DynamicDetailContainer

6 posts, 0 answered
  1. Stacey
    Stacey avatar
    291 posts
    Registered:
    18 Oct 2012
    06 May 2013
    Link to this post
    I have a module widget where I am calling out to a code file that handles some extra logic for the DynamicDetailContainer.  I can access the containers databound events and even the controls within the LayoutTemplate just fine, but I am trying to figure out how one could get a click event for a button to fire.

    I can successfully find the button within detailsContainer_DataBound, but any attempt to assign it a click event or command argument approach seems to be ignored.  I am guessing I am too far into the page lifecycle at this point to do that?

    I can move the button outside of the DynamicDetailsContainer and bind it that way just fine.  Wondering how I could do this within the the control if possible?

    Here is what I tried: 
    protected void detailContainer_DataBound(object sender, EventArgs e)
            {
                var container = sender as DynamicDetailContainer;
                var button = (Button)container.Controls[0].FindControl("submitButton");
     
    if (button != null) button.Click += button_Click;  //This is not null
     
    }
     
    protected void button_Click(object sender, EventArgs e) //this is never reached
    {
     
    }


  2. Randy Hodge
    Randy Hodge avatar
    96 posts
    Registered:
    03 Nov 2014
    09 May 2013
    Link to this post
    Hello Stacey,

    The click event doesn't work in a ListView. Try using OnCommand and catch it when it bubble up to the ListView.
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.command%28v=vs.100%29.aspx

    All the best,
    Randy Hodge
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Stacey
    Stacey avatar
    291 posts
    Registered:
    18 Oct 2012
    09 May 2013 in reply to Randy Hodge
    Link to this post
    I had already tried using OnCommand and that does not fire either.  I am not sure what I am missing here.  The below code runs except for the command event never triggers.  The button is found it just never does anything after that point.  That is why I wondered if it was already too late in the the page cycle to do this.  I ended up moving the button outside of the DynamicDetailContainer to get on with life, but if you see something I missed I would love to know.

            protected void detailContainer_DataBound(object sender, EventArgs e)
            {
                var container = sender as DynamicDetailContainer;
                var repeater = (Repeater)container.Controls[0].FindControl("ImageListRepeater");
     
                if (repeater != null)
                    repeater.ItemDataBound += repeater_ItemDataBound;
     
                var button = (Button)container.Controls[0].FindControl("submitButton");
                if (button != null)
                {
                    button.Command += button_Command;
                    button.CommandName = "Test";
                    button.CommandArgument = "0";
                }
    }
  4. Randy Hodge
    Randy Hodge avatar
    96 posts
    Registered:
    03 Nov 2014
    14 May 2013
    Link to this post
    Hello Stacey,

    You can't get to the button event directly. You have to subscribe to the ListView's ItemCommand event.

    This will fire when any button in the ListView is clicked.

    I hope this helps you.

    All the best,
    Randy Hodge
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Stacey
    Stacey avatar
    291 posts
    Registered:
    18 Oct 2012
    14 May 2013 in reply to Randy Hodge
    Link to this post
    Randy,

    Thanks for bearing with me here, but this is not a ListView...although I guess it probably is based off one.  The control in the widget template is <sf:DynamicDetailContainer ID="detailContainer" runat="server">

    I looked all around and even in the API documentation at DynamicDetailContainer and did not see that it has an ItemCommand event that I can tie into.  I even tried to assign is in code behind, but intellisense was throwing errors and I could not build with it.  Is there a specific namespace I need to access ItemCommand for DynamicDetailContainer?
  6. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    02 Dec 2016
    17 May 2013
    Link to this post
    Hi Stacey,

    We have managed to come up with a workaround, which, although not the most elegant one, should do the job. What I'm doing is checking the Form Keys in the request passing through Page_Load on PostBack. If the request has been initiated by the button, it (its client Id, actually) will be present in the list of AllKeys:
    Copy Code
    protected void Page_Load(object sender, EventArgs e)
            {
                if (IsPostBack)
                {
                    if (Request.Form.AllKeys.Contains("ctl19$ctl00$ctl00$Button1"))
                    {
                        //execute code here
                    }
                }
     
            }


    Regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
6 posts, 0 answered