?
Solved

making a composite control in asp.net 2.0

Posted on 2006-11-22
6
Medium Priority
?
341 Views
Last Modified: 2012-05-05
Hi

I am using asp.net 2.0. I want to create a composite control that consists of a graphic next to a link button. The graphic and the link button are laid out in a table.

I was looking for some pointers on where to start. Specifically how do i make sure my composite control raises a click event which my main page can respond to. How do i get the control to render so that the button and graphic are laid out in a table.

thanks a lot

andrea
0
Comment
Question by:andieje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:kraffay
ID: 17999954
vb or c#?
0
 

Author Comment

by:andieje
ID: 18002872
dont mind
0
 
LVL 9

Accepted Solution

by:
kraffay earned 2000 total points
ID: 18021562
You have to build a two column table in a ascx file (Add New Item...Web User Control):

<%@ Control Language="C#" ClassName="EEControl" %>
<table>
    <tr>
        <td style="width: 100px">
            <asp:Image ID="Image1" runat="server" ImageUrl="http://www.experts-exchange.com/images/vipAccess.gif" /></td>
        <td style="width: 100px">
            <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton></td>
    </tr>
</table>

Now we need to wire up an event so that the page hosting the control know when the button was clicked.  Here's the code-behind:

public partial class EEControl : System.Web.UI.UserControl
{
    public event EventHandler Clicked;

    protected void OnClicked(EventArgs e)
    {
        if (Clicked != null)
        {
            Clicked(this, e);
        }
    }

   
    protected void Page_Load(object sender, EventArgs e)
    {
        LinkButton myLinkButton = new LinkButton();
        myLinkButton.Click += new EventHandler(this.LinkButton1_Click);

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {

        OnClicked(EventArgs.Empty);

    }

}

Now we can embed our control on any page and interact with it:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EEControlHost.aspx.cs" Inherits="EEControlHost" %>
<%@ Register Src="EEControl.ascx" TagName="EEControl" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:EEControl ID="EEControl" runat="server" OnClicked="EEControl_OnClicked"  />
    </div>
    </form>
</body>
</html>

Here's the code behind for our container page:

public partial class EEControlHost : System.Web.UI.Page
{

    protected void EEControl_OnClicked(object sender, EventArgs e)
    {

        Response.Write("You clicked the User Control");

    }
}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:andieje
ID: 18076985
Hi

that's great - thanks very much

However, I would like to make this control implement the IButtonControl interface. How would i do that? I want the control to server as  a default button for the page

thanks
andrea
0
 
LVL 9

Expert Comment

by:kraffay
ID: 18077093
Try this:

public partial class EEControl : IButtonControl
0
 

Author Comment

by:andieje
ID: 18088329
but it doesnt implement any of the properties of the interface like validation group???
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question