User Control inside User Control

I have an ASPX with user controls in it called UC1.
There is another user control called UC2 within user control UC1.(UC1 - parent , UC2 - child)

What I need to do is to pass value of the text box that’s located inside user control UC1 to UC2.

This is the code I put into  user control UC1. How to I read it in User control UC2?

 

   Public ReadOnly Property propCountryName() As TextBox
        Get
            Return Me.txtCountrygName
        End Get
    End Property
 

 Thank you


100 years live, 100 years learn
0
Access
6/1/2007 6:29:26 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

7 Replies
1017 Views

Similar Articles

[PageSpeed] 41
Get it on Google Play
Get it on Apple App Store

You can define a property inside the UC1 and UC2. Page will fill in the property inside UC1 and then UC1 will fill in the property inside UC2.

Does this help?
Regards


Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
0
haidar_bilal
6/1/2007 1:24:28 PM

I defined property in UC1(in my original post) , but i don't get how to define it in UC2?

Please help.

 Thank you

 


100 years live, 100 years learn
0
Access
6/1/2007 2:09:03 PM

Hi,

You could use the Parent property of the child control to access the parent User Control: 

MyParentUC parentUc = this.Parent as MyParentUC; //just a type cast, in case you don't know C#
string myValue = parentUC.MyStringProperty;

 But a better way would be to expose a read/write property on the Child User Control (uc2), and set its value when the value is accessed inside the property on UC1. This is suggestion given above I believe.

Rich


Please mark any responses as Answers if they helped you solve your problem
0
rrmarriott
6/1/2007 4:21:52 PM

Thanks for reply.

I'm doing it in ASP.NET

In UC1(parent) i have:

Public ReadOnly Property propDrugName() As TextBox
        Get Return Me.txtDrugName
        End Get
    End Property

 

In UC2(child)  i have:  

1    Private parentUc As UC1 = CType(Me.Parent, UC1)
2    Private myValue As String = parentUc.propCountryName .Text
3    
 
 But but it gives me an error on the second line saying: System.NullReferenceException: Object reference not set to an instance of an object
 Thank you

 


100 years live, 100 years learn
0
Access
6/1/2007 5:56:36 PM

You don't need to do any casting in here!

Define a property on the inside UC, then add an instance of the inside UC inside the main UC, then place main UC inside the page.

Now when you are in the main UC you can access the property inside the inside UC as UC2.PropertName and inside the page you can access UC1.PropertryName.

Does this help?
Regards


Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
0
haidar_bilal
6/3/2007 8:16:11 PM

 


100 years live, 100 years learn
0
Access
6/4/2007 5:04:18 AM
Thanks for reply, I’m sure it will work what you suggested, but I’ve got a help from another forum member with less code to write:  

Dim tb As TextBox = CType(Parent.FindControl("TextBox1"), TextBox)

   it has to be placed in UC1. Thanks again.

 


100 years live, 100 years learn
0
Access
6/4/2007 5:05:25 AM
Reply:

Web resources about - User Control inside User Control - asp.net.getting-started

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

TERROR IN JAKARTA: 'Situation under control' after explosions, gunfire erupt in Indonesian capital
At least six people are dead, including three police officers, after several explosions at the Sarinah shopping mall in an apparent multi-site ...

DFES downgrades bushfire in Dunsborough as it is contained, but not under control
A BUSHFIRE south of Dunsborough has been contained but is not yet under control.

WA fires: threatening Jindalee blaze brought under control
A fire that was at one stage a threat to lives on homes in Jindalee on Thursday has been brought under control.

Queensland police shut down out-of-control party in Berserker, Rockhampton
Police shut down a party of 150 young people who had gathered at a house in Berserker, Rockhampton on Friday night.

Contextual and Granular Notification Controls
... written a lot about notifications, at one point calling the notifications screen “my home screen.” But I don’t like how we are forced to control ...

ESI cost control and networks
There is an interesting discussion thread on Twitter about how the way Medicare for All saves money is by significantly reducing provider, device, ...

While No One Was Watching, Obama Took Control of the Courts
... and President Obama’s legacy.” It didn’t favor conservatives but there was a dramatic shift to the far left. The appellate is under the control ...

Sanders Backs Gun Control Legislation Ahead of Democratic Debate
Hillary Clinton's campaign calls her rival's move a "debate-eve conversion."

Apple has landed a very rare sponsorship deal to ensure it has control of the hottest ticket in San Francisco ...
Apple has signed up for the first time to become a sponsor of the Super Bowl Host Committee, Daniel Roberts at Yahoo Finance reported. It's ...

Resources last updated: 1/17/2016 9:29:47 PM