The Edit button in View failed to open the page on DotNetNuke 6.2.4

Oct 31, 2012 at 6:12 AM
Edited Oct 31, 2012 at 6:21 AM

First of all. Thank you Chris! Like your videos very much.

When I followed the Task Manager - Part 22: Creating the Edit Button, the Edit button in the view control failed to open a popup window like the 'Edit Module' button does in the 'Manage' panel. The Edit button simply returned me an error page that says 'Internet Explorer cannot display the webpage'.

My development environment:

  • DotNetNuke 6.2.4 
  • .NET 4
  • Visual Studio 2010 Pro
  • IIS7 on Windows 7
  • SQL Server 2008

The code that's taking care of the Edit button is 

public void rptTaskListOnItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                Response.Redirect(EditUrl(string.Empty, string.Empty, "Edit", "tid=" + e.CommandArgument));
            }

The Response.Redirect(....) method failed me.

I have the 'Enable Pop-Ups?' checked under 'Admin>Site Settings>Advanced Settings>Usability Settings'. When I uncheck the 'Enable Pop-Ups?', the Edit button works by giving me the Edit user control as a static content in the page as opposed to a popup page. 

For some reason I really want to make the Edit button to bring up the popup page, like other Edit or Settings pages do in the DNN6.2.4. So I keep pulling my hair like crazy, then I found a solution.

Basically I disable the Response.Redirect and give a 'href' attribute for the Edit button in the rptTaskListOnItemDataBound. So in the rptTaskListOnItemCommand method, I commented out the following lines:

        public void rptTaskListOnItemCommand(object source, RepeaterCommandEventArgs e)
        {
            /*if (e.CommandName == "Edit")
            {
                Response.Redirect(EditUrl(string.Empty, string.Empty, "Edit", "tid=" + e.CommandArgument));
            }*/

            if (e.CommandName == "Delete")
            {
                TaskController.DeleteTask(Convert.ToInt32(e.CommandArgument));
            }

            Response.Redirect(DotNetNuke.Common.Globals.NavigateURL());
        }

and  the insert this line 

 lnkEdit.Attributes["href"] = EditUrl(String.Empty, String.Empty, "Edit", "tid=" + curTask.TaskId);

in the rptTaskListOnItemDataBound method

        protected void rptTaskListOnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var lnkEdit = e.Item.FindControl("lnkEdit") as LinkButton;
                var lnkDelete = e.Item.FindControl("lnkDelete") as LinkButton;

                var pnlAdminControls = e.Item.FindControl("pnlAdmin") as Panel;

                var curTask = (Task)e.Item.DataItem;

                if (IsEditable && lnkDelete != null && lnkEdit != null && pnlAdminControls != null)
                {
                    pnlAdminControls.Visible = true;
                    lnkDelete.CommandArgument = lnkEdit.CommandArgument = curTask.TaskId.ToString();
                    lnkDelete.Enabled = lnkDelete.Visible = lnkEdit.Enabled = lnkEdit.Visible = true;

                    ClientAPI.AddButtonConfirm(lnkDelete, Localization.GetString("ConfirmDelete", LocalResourceFile));

                    lnkEdit.Attributes["href"] = EditUrl(String.Empty, String.Empty, "Edit", "tid=" + curTask.TaskId);
                }
                else
                {
                    pnlAdminControls.Visible = false;
                }
            }
        }

Build it, reload the page, and It works. I just want to share this with other developers like me just starting module development.

I don't know the exact reason why this works. If someone can point that out, I'd appreciate it.

Coordinator
Oct 31, 2012 at 3:04 PM

This works because the original code for the TaskManager series was for DNN5 which didn't have popups, so the response.redirect worked fine, but in DNN6 you have to change it to make things work.

I will be completely redoing the TaskManager series for DNN7 in the next couple of months and will have all sorts of new ways to do things.

Oct 31, 2012 at 3:24 PM

Thank you Chris. Will there be a training video for settings control for DNN7? 

Coordinator
Oct 31, 2012 at 3:26 PM

Yes, eventually, but it will probably be December/January before I can get to the TaskManager series due to my travel schedule

Jan 7, 2013 at 3:33 AM

Is a 7.0 version of the Task Manager still potentially going to be available this month?

Coordinator
Jan 17, 2013 at 5:24 PM

I am working on it now, but it will be a ground up rewrite and likely be short the ContentItem features at first due to the approach I am taking for the tutorial series.