Button event in DynamicDetailContainer

Posted by Community Admin on 04-Aug-2018 18:47

Button event in DynamicDetailContainer

All Replies

Posted by Community Admin on 06-May-2013 00:00

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
 


Posted by Community Admin on 09-May-2013 00:00

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

Posted by Community Admin on 09-May-2013 00:00

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";
            

Posted by Community Admin on 14-May-2013 00:00

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

Posted by Community Admin on 14-May-2013 00:00

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?

Posted by Community Admin on 17-May-2013 00:00

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

This thread is closed