User control with event : Control Action « User Control and Master Page « ASP.Net

ASP.Net
1. ADO.net Database
2. Ajax
3. Asp Control
4. Collections
5. Components
6. Data Binding
7. Development
8. File Directory
9. HTML Control
10. Language Basics
11. Login Security
12. Mobile Control
13. Network
14. Page
15. Request
16. Response
17. Server
18. Session Cookie
19. Sitemap
20. Theme Style
21. User Control and Master Page
22. Validation by Control
23. Validation by Function
24. WebPart
25. WPF
26. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » User Control and Master Page » Control Action 
User control with event


<%@ Page language="c#" %>
<%@ Register TagPrefix="uc1" TagName="Control" Src="Control.ascx" %>
<script runat="server">
  void MultipleReached(object sender, EventArgs e) {
    Message.Text="Congratulations!";
  }
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
<html>
  <body MS_POSITIONING="FlowLayout">
    <form id="Control" method="post" runat="server">
      <uc1:Control id="Control1" 
                   runat="server" 
                   Multiple="5" 
                   OnMultipleReached="MultipleReached"></uc1:Control>
      <asp:Label ID="Message" Runat="server" EnableViewState="False" />
     </form>
  </body>
</html>

File: Control.ascx

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

File: Control.ascx.cs

namespace Control
{
  using System;
  using System.Data;
  using System.Drawing;
  using System.Web;
  using System.Web.UI.WebControls;
  using System.Web.UI.HtmlControls;

  public abstract class Control : System.Web.UI.UserControl
  {
    protected static readonly object EventMultipleReached = new Object();
    protected System.Web.UI.WebControls.Label OutputLabel;
    private int multiple = 10;
    public int Multiple 
    {
      get 
      {
        return multiple;
      }
      set
      {
        multiple = value;
      }
    }
    private void Page_Load(object sender, System.EventArgs e)
    {
      if(Application["count"== null)
        Application["count"0;
      Application.Lock();
      Application["count"(int)Application["count"1;
      Application.UnLock();

      if((int)Application["count"% Multiple == 0)
        OnMultipleReached(EventArgs.Empty);

      OutputLabel.Text = Application["count"].ToString();
    }

    public event EventHandler MultipleReached 
    {
      add 
      {
        Events.AddHandler(EventMultipleReached, value);
      }
      remove
      {
        Events.RemoveHandler(EventMultipleReached, value);
      }
    }

    public virtual void OnMultipleReached(EventArgs e)
    {
      EventHandler MultipleReachedHandler = (EventHandler)Events[EventMultipleReached];
      if (MultipleReachedHandler != null)
      {
        MultipleReachedHandler(this, e);
      }
    }

    override protected void OnInit(EventArgs e)
    {
      InitializeComponent();
      base.OnInit(e);
    }
    
    private void InitializeComponent()
    {
      this.Load += new System.EventHandler(this.Page_Load);

    }
  }
}

 
Related examples in the same category
1. User Control with Events (VB.net)
2. Clear textbox in a user defined control (VB.net)
3. User control with event (VB)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.