Custom Control to Custom Control communication using event delegate mech.

I have a custom control “AddressPicker” that displays dynamic address information of a user. BY dynamic I mean based on the database call it checks how may addresses a user has and it displays it. There is a “Use this Address” button at the bottom of each address information which is generated dynamically too as a part of CreateChildControl. If a user click on this button I need to pass this information to another custom control namely “AddressConsumer” which in turn uses this information for further processing.My Controls are inherited WebCOntrol,INamingContainer

I am using the event delegate mechanism to pass information from one control to other

This is a code snippet from AddressPicker control

public delegate void AddressClickEventHandler(object sender, AddressClickEventArgs e); public event AddressClickEventHandler AddressClick;protected virtual void OnAddressClick(AddressClickEventArgs args)        {            if (AddressClick != null)            {                // Invoke the delegate.                AddressClick(this, args);            }       

}

AddressClickEventHandler is a class inherited from EventArgs which I am using for getting/setting address fields

This is the “Use This Address”  button Click

protected void btnUseThisAddress_Click(object sender, EventArgs e)

{

AddressClickEventArgs args = new AddressClickEventArgs();                    

args.FirstName = lblFirstName.Text;            args.MiddleInitial = lblMiddleInitial.Text;            args.LastName = lblLastName.Text;            args.Suffix = lblSuffix.Text;            args.Address1 = lblAddress1;             

OnAddressClick(args);

}

This is a code snippet from AddressConsumer control.  

public void AddressClick(object sender, AddressClickEventArgs args)

{txtFirstName.Text = args.FirstName;            txtMiddleInitial.Text = args.MiddleInitial;            txtLastName.Text = args.LastName;            txtSuffix.Text = args.Suffix;           

txtAddress1.Text = args.Address1;

}

I am testing this Controls by dropping them on a Web Page and implementing

protected void Page_Load(object sender, EventArgs e)        {            AddressPicker.AddressClick += new AddressPicker.AddressClickEventHandle(AddressPicker1_AddressClick);        }         protected void AddressPicker1_AddressClick(object sender, AddressClickEventArgs e)        {            AddressConsumer.AddressClick(sender, e);        }       

Here is how I am creating Child Controls & Rendering it

protected override void CreateChildControls()        {            Controls.Clear();            addressList = GetAddressList()     

foreach(ADDRESS IN THE ADDRESSLIST)

{Gets the individual value of address filedsCreateChildControlName(pass extracted Name value from List);CreateChildControlAddress(pass extracted Address value from List);& so on} While rendering I am doing the same stuff and then rendering it. 

WELL HERE IS THE PROBLEM…… IT WORKS FINE WHEN USER HAS ONLY ONE ADDRESS INFORMATION. BUT WHEN THE USER HAS MORE THAN ONE INFORMATION WHEN I CLICK ON “USE THIS ADDRESS” BUTTON IT ALWAYS PASSES THE SAME VALUEs IRRESPECTIVE OF WHICH BUTTON I CLICKED.

After reading lot of forums I  guess the part of the problem is I may have to use RaiseBububble and OnBUbble  PLUS I need to add all the child controls in a container in a ControlCollection  so that it can uniquely identify the child control while generating it dynamically but I am not sure how to incorporate in this scenario. Any help would be greatly appreciated.

OR COULD  SOMEONE PLEASE POINT ME TO ANY ARTICLE SIMILAR TO ABOVE SITUATION OR POST A CODE SNIPPET FOR THE FOLLOWING SCENARIO LISTED BELOW :

"Adding a TextBox and a BUtton as One Control  and then repeatedly  adding this Control  to a Container in a Control collection and then later on using a ONBubble and RaiseBubble to find out exactly which Button is clicked and extracting clicked button corresponding TextBox value."

THANK YOU.

 

 

0
user_resu
3/14/2009 7:06:18 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

1 Replies
1079 Views

Similar Articles

[PageSpeed] 50

Hi,

user_resu:
"Adding a TextBox and a BUtton as One Control  and then repeatedly  adding this Control  to a Container in a Control collection and then later on using a ONBubble and RaiseBubble to find out exactly which Button is clicked and extracting clicked button corresponding TextBox value."

If this is what you need you can try the following code:

cs:

 

 

public class MyControl : WebControl {

TextBox tb = new TextBox();

Button btn = new Button();protected override void OnInit(EventArgs e)

{

base.OnInit(e);

btn.Click += new EventHandler(btn_Click);

btn.Text = "Click Me";

this.Controls.Add(tb);this.Controls.Add(btn);

}

void btn_Click(object sender, EventArgs e)

{

//Test

Page.Response.Write(tb.Text);

}

}

 

aspx:

<asp:Panel ID="Panel1" runat="server">

<cc2:MyControl ID="MyControl1" runat="server" />

<cc2:MyControl ID="MyControl2" runat="server" />

<cc2:MyControl ID="MyControl3" runat="server" />

</asp:Panel>


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
3/16/2009 1:58:43 AM
Reply:

Similar Artilces:

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingcompositecontrols.asp Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Dynamic custom control on custom control
What I'm trying to do is create a module for use within a larger page.  The page itself is an order form, which will have typical payment info (address, credit card, etc.), and the ability to select what you are paying for.  Our clients will have several options in how they want the page setup.  They can either have a single form, or they can have each module on it's own page.  They can also have all the selected items fire in a single transaction, or have a seperate transaction for each item selected.  And they can limit the total number of transactions a person can...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. http://forums.asp.net/p/1397433/3010100.aspx#3010100 I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal asp.net page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer asp.net sites and/or SharePoint sites why don't you just create Web Par...

Custom Control within a Custom Control
I have two individual custom controls say custom cc1 and cc2. cc1 is communicating to cc2 using event delegate mechanism.I have tested the behaviour by dropping cc1 and cc2 onto a Web Page and it works fine. I want to create a third custom control say cc3 which should contain both cc1 and cc2. So that if i drag and drop cc3 onto a Web Page i can acheive exactly what i am doing above. The problem is that i am not sure how to call/register a custom control within a custom control ? Any clue ? Thanks!! Hi, Do you mean adding custom control to custom control? I think you can use the same wa...

Custom event for Custom server control
  Hi All, I have a custom server control (Multi selection drop downlist). This control contains AspxEditButton control(which is like textbox with button), check box list control and panel.I have to display all selected values in AspxEditButton at control is leaving that panel. How can i create LostFocus event for panel . Please anyone help meRegards, Anu All I can think of, is that there is a javascript "onblur" you could look into, maybe you could use some AJAX techniques to make that JavaScript event fire a server side ev...

Custom Events in Custom Server Control
 Hi There I've created a custom server control. I have extended it by adding my own event which fires in one of the aggregated control's event handlers. My probelms is that I would like to be able to specify the event handler for the event from the aspx file as a tag attribute.Does anyone know how to link the attribute of a customer server control tag in the aspx file to a custom event in the class source for the control?   I've done this several times with Custom Controls.  All I do is declare the event in the CustomControl's class public...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Creating Custom Controls With Custom Controls Inside Of Them
Hello, I am trying to create a custom control for creating tabs. The idea is that our designer can just use the control tags to generate the tabs.  The problem that I am running into is that I want to be able to have a custom control that allows any number of child custom controls. So there would be a TabContainer Control, and within that there would be any number of tabs.  The idea is similar to how an asp:DropDown list can have any number of ListItems within them.  Here is my code, any help is appreciated. 1 <!-- TAB CONTAINER -->2 <%@ Control Language=&...

Custom controls called from inside other custom controls???
I'm fairly new to writing controls in ASP.NET so, forgive the I am trying to create a base page class which will call 3 custom controls. This base page class will span across multiple projects hence the reason I am not creating user controls. These 3 custom controls are: 1. TopNav-uses render method to display an HTML table with graphics for top navigation. 2. ImagePairs-uses prerender method to add javascript code to manage what graphic is displayed in TopNav onMouseOver and onMouseOut 3. MgrHeader-uses render method to display an HTML table with s...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

Using a user control in a custom server control.
I've created a custom server control and am trying to add a user control to the rendering of the server control.  Is this possible?  If so, hints as to how this is done would be GREATLY appreciated!  Thanks in advance for considering an answer to this question. Wendi Use the LoadControl method. For example:   Controls.Add(LoadControl("~/controls/login.ascx"))Steven BeyRecursion: see Recursion My server control renders a table with x number of rows.  I want to add a user control to each row of the table, last column.  I do not know how ...

handling events for controls in custom server control
Hi,     I am having a problem in using server controls in ASP.Net, with C#.  I am trying to create a server control which contains 2 other server controls that I created (Called MyImageButton).  MyImageButton extends the standard ImageButton with some other properties & methods that I needed.  It therefore also has the 'OnClick' event.  From the original server control, I would like to handle the Click event for these 2 image buttons in the same server control.  Basically, this server control will show 2 images, ascending and descendin...

Web resources about - Custom Control to Custom Control communication using event delegate mech. - asp.net.custom-server-controls

Communication - Wikipedia, the free encyclopedia
) is the activity of conveying information through the exchange of ideas, feelings, intentions, attitudes, expectations, perceptions or commands, ...

VoIP Business, VoIP Technology, VoIP Security - Fierce Enterprise Communications
Visit FierceVoIP for the latest updates in VoIP business, unified communications, VoIP technology, mobile VoIP, VoIP security and more VoIP news. ...

Mobile News Online - The UK's leading mobile communication industry news site
This month, thousands of students will be starting university for the first time. Some will need new phones. Mystery Caller is on the case to ...

50 Million Small Businesses Using Facebook Pages; New Communications Tools Launched
Facebook announced Tuesday that more than 50 million small businesses are using pages , and the social network rolled out some new communications ...

New privacy platform protects enterprise communication
Enterprise customers are increasingly concerned about the security of their mobile communications, as well as the ability to deliver auditing ...

"Smoking high potency 'skunk-like' cannabis can damage a crucial part of the brain responsible for communication ...
... The researchers specifically examined the corpus callosum, the largest white matter structure in the brain, which is responsible for communication ...

Uber hired a new director of communications from Google, and she's cleaning house
A second round of layoffs has hit Uber's communications and policy team, Business Insider has learned. Combined with an earlier round of layoffs ...

Frontier Communications Receives Final Regulatory Approval in California to Acquire Verizon Operations ...
Frontier Communications Corporation (NASDAQ: FTR) announced today that the California Public Utilities Commission (CPUC) unanimously voted to ...

Congress considers new rules on encrypted communications - Videos - CBS News
To better track terrorists, law enforcement officials want greater access to messaging apps that encrypt communications. Congress is considering ...

Brocade, Cisco, Juniper leading networking and communication hardware market
Channelnomics Brocade, Cisco, Juniper leading networking and communication hardware market Channelnomics Brocade, Cisco, HP, Huawei, Avaya ...

Resources last updated: 12/12/2015 3:27:32 AM