How to add two user controls in same page?

Posted by Hardcoder under ASP.NET on 11/1/2009 | Views : 4790 | Status : [Member] | Replies : 5
Hi All,
I Like to add two same user controls on a single page.

For example -
I have a user control for Address (with following four fields - Address Line1, Address Line2, City, Country)
Now I want to add this on a page where I need two address
1. Local Address
2. Permanent Address.

I want to use the User Control for this, please let me know how to proceed with this.


Thanks,

hardcoder | www.moirf.com
https://www.facebook.com/JobsSoftware



Responses

Posted by: Vuyiswamb on: 11/1/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
I dont understand your question

Thank you for posting at Dotnetfunda
[Administrator]

Hardcoder, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Poster on: 11/2/2009 [Member] Starter

Up
0
Down
Go through http://www.dotnetfunda.com/articles/article16.aspx article.

In summary, you need to declare the property in usercontrol like Name, Address1, Address2 etc.

Call the user control and set its respective property and call on the page.

This might give u some idea.

Thanks

Hardcoder, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakhangarg on: 11/2/2009 [Member] [Moderator] Silver

Up
0
Down
Hi -

First of all add Register Directive as :
<%@ Register Src="../Address.ascx" TagName="Address" TagPrefix="uc2" %>

now if you want to use it twice then use like this:
<uc2:Address ID="Address1" runat="server" />
<uc2:Address ID="Address2" runat="server" />

Thanks & Regards
Lakhan Pal Garg

Hardcoder, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hardcoder on: 11/2/2009 [Member] Starter

Up
0
Down
Yes you are right, we can use it by Diff Id, now the problem is how should I distinguish that AdressLine1 belongs to UC1:Address1 or UC1:Address2?


hardcoder | www.moirf.com
https://www.facebook.com/JobsSoftware

Hardcoder, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakhangarg on: 11/2/2009 [Member] [Moderator] Silver

Up
0
Down
You can Access this using

For First Control:
Address1.Address_Line1
Address1.Address_Line2
Address1.City
Address1.State
Address1.Country

For Second Control:
Address2.Address_Line1
Address2.Address_Line2
Address2.City
Address2.State
Address2.Country

Thanks & Regards
Lakhan Pal Garg

Hardcoder, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response