Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

telerik -- supercharge your DNN websites
  Ads  
Engage Software - Training Partner for DotNetNuke
 


  Sponsors  

Meet Our Sponsors

SourceGear - Tools for Developers
.: CounterSoft :.
telerik
ExactTarget email software solutions
Merak Mail Server
WebSecureStores -- ASP.NET & DotNetNuke Hosting Solutions
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! (Pro...  Problem with CommandButton (DotNetNuke.UI.WebControls)
Previous Previous
 
Next Next
New Post 7/27/2008 1:48 AM
User is offline Michael Tobisch
36 posts
www.helferlein.com
10th Ranked


Problem with CommandButton (DotNetNuke.UI.WebControls) 

In the edit control of a module I am writing I use two CommandButton controls from DotNetNuke.UI.WebControls. The Markup looks like:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyModuleEdit.ascx.cs"
   Inherits="MyCompany.DNN.Modules.MyModule.UI.MyModuleEdit" %>
<%@ Register Assembly="DotNetNuke" Namespace="DotNetNuke.UI.WebControls" TagPrefix="dnn" %>
...
<dnn:CommandButton ID="CancelButton" runat="server" CausesValidation="false"
   ResourceKey="cmdCancel" CssClass="CommandButton"
   ImageUrl="~/images/action_export.gif"
   OnClick="CancelButton_Click" />
...

and the code behind:

namespace MyCompany.DNN.Modules.MyModule.UI
{
   public partial class MyModuleEdit : PortalModuleBase
   {
      ...
      protected void CancelButton_Click(object sender, EventArgs e)
      {
         try
         {
            Response.Redirect(Globals.NavigateURL(), true);
         }
         catch (Exception ex)
         {
            Exceptions.ProcessModuleLoadException(this, ex);
         }
      }
      ...
   }
}

When I use an asp:LinkButton control insted of the dnn:CommandButton, the thing works a expected and returns to the module's main view control. When I use the dnn:CommandButton, it fires a postback but does not return to the view control. In debug mode I recognized that the eventhandler is never executed. When I delete the event handler from the code there is no runtime error saying that the member CancelButton_Cllick dows not exist.

I also looked at the source code from the DNN Links Module, it is done in the exactly same way as here (only in VB insted of C#).

What works is the following code:

...
<dnn:CommandButton ID="CancelButton" runat="server" CausesValidation="false"
   ResourceKey="cmdCancel" CssClass="CommandButton"
   ImageUrl="~/images/action_export.gif"
   OnInit="CancelButton_Init" />
...

and

...
      protected void CancelButton_Init(object sender, EventArgs e)
      {
         this.CancelButton.Click += new EventHandler(CancelButton_Click);
      }

      protected void CancelButton_Click(object sender, EventArgs e)
      {
         try
         {
            Response.Redirect(Globals.NavigateURL(), true);
         }
         catch (Exception ex)
         {
            Exceptions.ProcessModuleLoadException(this, ex);
         }
      }
...

Any ideas?

Michael

 
New Post 7/27/2008 11:48 AM
User is offline Ian Robinson
651 posts
www.engagesoftware.com
7th Ranked


Re: Problem with CommandButton (DotNetNuke.UI.WebControls) 

Hey Michael,

This makes sense, as you'll need to either wire up the event in the markup or in the code behind. However, defining a new event for OnInit to wire up the event is going a little bit out of your way. You should be able to put the contents of the CancelButton_Init handler into a "page lifecycle" event that already exists in your code behind and remove the OnInit="CancelButton_Init" from the markup. It's my preference to wire up events in the code behind rather than in the markup ("separation of concerns...").

Here is an example from a project I had close at hand:

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += this.Page_Load;
            this.SearchButton.Click += this.SearchButton_Click;
            this.ReplaceButton.Click += this.ReplaceButton_Click;
        }

When you're using the LinkButton - do you notice that the event handler is wired up in the markup for you by default?

Hope that helps,

Ian


Ian Robinson
Engage Software
St. Louis, MO
314.966.4000



The leading provider of DotNetNuke support, training and custom development.
 
Previous Previous
 
Next Next
  Forum  General DotNetN...  Extend It! (Pro...  Problem with CommandButton (DotNetNuke.UI.WebControls)
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, please observe the following posting guidelines:

1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


Active Modules, Inc.
Creators of Active Forums, the best forum module for DotNetNuke
www.activemodules.com
DNNCovered.com - Your Offshore Dotnetnuke Partner
Dnncovered.com is the only Dotnetnuke offshore outsourcing center specializes in DNN skinning and module development with lowest pricing and quality service. Our staff is dedicated to websites based on DNN and our graphic designers are creative and imaginative well enough to provide customers the complete set of skinning solutions and packages
www.dnncovered.com
PointClick.Net DNN Solutions
DotNetNuke Hosting Platform for Business and personal use.
PointClick.Net Hosted Solutions

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP