Solved

making a composite control in asp.net 2.0

Posted on 2006-11-22
6
340 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 500 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Independent Software Vendors: 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 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