1

I have a two User control the name is UC_1.ascx & UC_2.ascx.

In my UC_1.ascx I have One Placeholder.

<asp:PlaceHolder id="placeHolderAddTimeReport" runat="server"></asp:PlaceHolder>

In my another usercontrol I have one textbox.

UC_2.ascx :

<asp:TexBox ID="txtName" runat="server"/>

I would like to bind UC_2 - textbox to UC_1.

How to do it ?

Please help me to solve.

Andrei
  • 55,890
  • 9
  • 87
  • 108
Dhamo
  • 91
  • 4
  • 14
  • is this duplicate of [this](http://stackoverflow.com/a/3013505/525251) Question? – rt2800 Jul 15 '15 at 07:11
  • nope. This what i need. Please help me to solve. – Dhamo Jul 15 '15 at 07:12
  • Are these controls on same page? If yes, you can handle data-binding using javascript; Handle Onchange evt on textbox `txtName` and find `placeHolderAddTimeReport` DOM element and update its data/CSS etc – rt2800 Jul 15 '15 at 07:15

1 Answers1

0

User controls are designed to be kind of independent pieces, so it won't be a good idea to do some coupling inside each other. However what you can do is expose necessary interface from UC_2 and use it in UC_1. Kind of the same way validators are bound to the controls they validate.

Simplistic example comes below. This is just an idea of what might be done. You know better what kind of binding you need.

In UC_2 have:

public string Name
{
    get { return txtName.Text; }
    set { txtName.Text = value; }
}

Similarly for other properties. And now in UC_1:

public string NameControlId
{
    get; set;
}

In the markup make sure to set this property:

<blah:UC2 ID="NameControl1" runat="server" />
<blah:UC1 ... NameControlId="NameControl1" />

And then just use it in UC1 to find the necessary control and use the Name property:

UC2 nameControl = (UC2)Page.FindControl(NameControlId);
nameControl.Name = "name from UC1";

Warning - FindControl method is not recursive, so the above code most likely won't work. You most likely will need a recursive version, which are plenty in the internet. Example.

Community
  • 1
  • 1
Andrei
  • 55,890
  • 9
  • 87
  • 108