fill controls of web user control from parent page
<p>i have two web user control in one the grid view is showing the result and the other contains the simply textboxes and the dropdowns that are basically created to edit that gridview items </p>

<p>the aspx.cs page code is </p>

<pre><code>GridView gView = PlaceHolder2.Controls[0].FindControl("grvBranches") as GridView;
int index = gView.SelectedIndex;

GridViewRow grd = gView.Rows[index];
Label lbl = (Label)grd.FindControl("lblID");

int rowid = 0;
int.TryParse(lbl.ToString(), out rowid);
</code></pre>

<p>In rowid i contains the id of that item which is selected </p>

<p>now i want to fill all the following items in webusercontrol</p>

<pre><code>&lt;div class="col2_form1"&gt;
 &lt;div class="form1_bar1"&gt;
    &lt;div class="form1_txt1_div"&gt;
        &lt;asp:Label ID="lblBranchName" runat="server" Text="Branch Name"&gt;
        &lt;/asp:Label&gt;
    &lt;/div&gt;
    &lt;div class="form1_txtfield_div"&gt;
        &lt;asp:TextBox runat="server" ID="txtBranchName" class="form1_TxtField" /&gt;
    &lt;/div&gt;
    &lt;div class="form1_txt2_div"&gt;
        &lt;asp:RequiredFieldValidator ID="RFVBranchName" ErrorMessage="*" Display="Dynamic"
            ValidationGroup="Save" ControlToValidate="txtBranchName" runat="server" /&gt;
        &lt;%--  &lt;asp:Label Text="Error" ID="lblBranchNameError" runat="server" /&gt;--%&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class="form1_bar2"&gt;
    &lt;div class="form1_txt1_div"&gt;
        &lt;asp:Label Text=" Organization Name" ID="lblOrganizationName" runat="server" /&gt;
    &lt;/div&gt;
    &lt;div class="form1_txtfield_div"&gt;
        &lt;asp:DropDownList ID="ddlOrganization" CssClass="form1_TxtField" runat="server"&gt;
        &lt;/asp:DropDownList&gt;
    &lt;/div&gt;
    &lt;div class="form1_txt2_div"&gt;
        &lt;%--&lt;asp:Label Text="Error" ID="lblOrganizationNameError" runat="server" /&gt;--%&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class=" form1_bar1"&gt;
    &lt;div class="form1_txt1_div "&gt;
        &lt;asp:Label Text="Address Line1" ID="lblAddresLine1" runat="server" /&gt;
    &lt;/div&gt;
    &lt;div class=" form1_txtfield_div"&gt;
        &lt;asp:TextBox runat="server" ID="txtAddresLine1" CssClass="form1_TxtField" /&gt;
    &lt;/div&gt;
    &lt;div class="form1_txt2_div "&gt;
        &lt;asp:RequiredFieldValidator ErrorMessage="*" Display="Dynamic" ValidationGroup="Save"
            ControlToValidate="txtAddresLine1" runat="server" /&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class=" form1_bar2"&gt;
    &lt;div class="form1_txt1_div "&gt;
        &lt;asp:Label Text="Address Line2" ID="lblAddresLine2" runat="server" /&gt;
    &lt;/div&gt;
    &lt;div class="form1_txtfield_div "&gt;
        &lt;asp:TextBox runat="server" ID="txtAddresLine2" CssClass="form1_TxtField" /&gt;
    &lt;/div&gt;
    &lt;div class="form1_txt2_div "&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class="form1_bar1 "&gt;
    &lt;div class="form1_txt1_div"&gt;
        &lt;asp:Label Text="Country" ID="lblCountry" runat="server" /&gt;
    &lt;/div&gt;
    &lt;div class="form1_txtfield_div " style="float: left;"&gt;
        &lt;asp:DropDownList ID="ddlCountry" AutoPostBack="true" CssClass="form1_TxtField" runat="server"
            OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged"&gt;
        &lt;/asp:DropDownList&gt;
    &lt;/div&gt;
    &lt;div class=" form1_txt2_div"&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class=" form1_bar2"&gt;
    &lt;div class="form1_txt1_div "&gt;
        &lt;asp:Label Text="State" ID="lblState" runat="server" /&gt;
    &lt;/div&gt;
    &lt;div class="form1_txtfield_div "&gt;
        &lt;asp:DropDownList ID="ddlState" AutoPostBack="true" CssClass="form1_TxtField" runat="server"
            OnSelectedIndexChanged="ddlState_SelectedIndexChanged"&gt;
        &lt;/asp:DropDownList&gt;
    &lt;/div&gt;
    &lt;div class="form1_txt2_div "&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class="form1_bar1 "&gt;
    &lt;div class="form1_txt1_div "&gt;
        &lt;asp:Label Text="City" ID="lblCity" runat="server" /&gt;
    &lt;/div&gt;
    &lt;div class="form1_txtfield_div "&gt;
        &lt;asp:DropDownList runat="server" CssClass="form1_TxtField" ID="ddlCity"&gt;
        &lt;/asp:DropDownList&gt;
    &lt;/div&gt;
    &lt;div class="form1_txt2_div "&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class="form1_bar2 "&gt;
    &lt;div class="form1_txt1_div "&gt;
        &amp;nbsp;
    &lt;/div&gt;
    &lt;div class="form1_txtfield_div"&gt;
        &lt;asp:Button Text="Save" Width="100px" runat="server" ID="btnSave" ValidationGroup="Save"
            OnClick="btnSave_Click" /&gt;
    &lt;/div&gt;
    &lt;div class="form1_txt2_div"&gt;
        &lt;asp:Label Text="" ID="lblMsg" Visible="false" runat="server" /&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p></p>

<p>i have a property on the webusercontrol as</p>

<pre><code>public string ABC_DEF
{
   set  {   txtABC.Text = value;       }
   get  {   return txtABC.Text;       }
}
</code></pre>

<p>and on the parent page i.e on the aspx page i call it as</p>

<pre><code>if (ViewState["controlname"] != null)
{
  PlaceHolder pl = MainPanel.FindControl(ViewState["controlname"].ToString()) as PlaceHolder;
  pl.Controls.RemoveAt(0);
}
Control uc = (Control) Page.LoadControl("~/usercontrols/control_forms/branch_aspx_form.ascx");

ViewState["path"] = "~/usercontrols/control_forms/branch_aspx_form.ascx";
ViewState["controlname"] = "PlaceHolder1";
PlaceHolder1.Controls.Add(uc);


branch_view[] branch_to_edit = EntityService.ServiceInstance.GetBranchByBranchID(row_id);

foreach (branch_view item in branch_to_edit)
{
       usercontrols.control_forms.branch_aspx_form branch_control = 
                 new usercontrols.control_forms.branch_aspx_form();
      branch_control.ABC_DEF = " hello";  // Call property here
}
</code></pre>

<p>thanks 
Gurbax</p>
