wxysky

eduAdmin

博客园 首页 新随笔 联系 订阅 管理

摘自一个国外的论坛。

First the Send.ascx

<%@ Control Language="c#" AutoEventWireup="false" Codebehind="Send.ascx.cs" Inherits="YourNamespace.Send" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<table border="0" cellpadding="5" cellspacing="0">
 <tr>
  <td><asp:TextBox id="txtText" runat="server" CssClass="NormalTextbox"></asp:TextBox></td>
  <td><asp:Button id="btnSend" runat="server" Text="Send" CssClass="CommandButton"></asp:Button></td>
 </tr>
</table>

Then the Send.ascx.cs
namespace YourNamespace
{
//leaving out the standard using statements for brevities sake
//I prefer to qualify using statements to not have so much clutter in the latter parts of code
 using DotNetNuke;
 using DotNetNuke.Entities.Modules;
 using DotNetNuke.Entities.Modules.Communications;

 public class Send : PortalModuleBase, IModuleCommunicator  //This is part of the key here
 {
  protected System.Web.UI.WebControls.TextBox txtText;
  protected System.Web.UI.WebControls.Button btnSend;

  public event ModuleCommunicationEventHandler ModuleCommunication; //Here's the implementation of the event, and the part that wasn't horribly intuitive.

//standard generated code omitted

  private void btnSend_Click(object s, System.EventArgs e)
  {
//create an instance of the ModuleCommunicationEventArgs and populate it with what you want to send.
   ModuleCommunicationEventArgs oArgs = new ModuleCommunicationEventArgs();
   oArgs.Text = txtText.Text;
   oArgs.Sender = "Sender";
   oArgs.Target = "Receiver";
   if(ModuleCommunication != null)
    ModuleCommunication(this, oArgs);
  }
 }
}

Then the Receiver.ascx

<%@ Control Language="c#" AutoEventWireup="false" Codebehind="Receive.ascx.cs" Inherits="YourNamespace.Receive" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:Label id="lblReceive" runat="server" CssClass="NormalRed"></asp:Label>

Lastly the Receiver.ascx.cs

namespace YourNamespace
{
 using DotNetNuke;
 using DotNetNuke.Entities.Modules;
 using DotNetNuke.Entities.Modules.Communications;

 public class Receive : PortalModuleBase, IModuleListener //again, we implement IModuleListener here
 {
  protected System.Web.UI.WebControls.Label lblReceive;

  private void Page_Load(object sender, System.EventArgs e)
  {
   lblReceive.Text = "Listening...";
  }

  #region Web Form Designer generated code //Nothing changed here

  public void OnModuleCommunication(object s, ModuleCommunicationEventArgs e) //This is what to do when you "hear" something
  {
      lblReceive.Text = e.Text;
  }
 }
}

 

--------------------------------------------------------------------------------
Kevon

posted on 2006-03-07 22:18  无名  阅读(1322)  评论(1编辑  收藏  举报