← Tutti gli articoli
FIndControl within Page ( within a MasterPage ) from a UserControl Code Behind
11 February 2011 ·
Asp.Net · Article ·
447 visite
I am trying to find a control which is within my aspx page within a MasterPage.
I have a master page with the following ContentPlaceHolder:
-
< asp:ContentPlaceHolder ID = "cphMiddle" runat = "server" >
-
</ asp:ContentPlaceHolder >
In the content page I use the following web user control:
- < %@ Register Src = "WebControls/ucFinanziamentoAttachments.ascx" TagName = "ucFinanziamentoAttachments"
- TagPrefix = "uc2" % >
and the following content
- <asp:Content ID="Content3" ContentPlaceHolderID="cphMiddle" runat="Server">
- <asp:HiddenField ID="hf_ID_SpidFinanziamentoStato" runat="server" />
- <uc2:ucFinanziamentoAttachments ID="FinanziamentoAttachments" runat="server" />
- </asp:Content>
Now I need to read the hf_ID_SpidFinanziamento in the web user control.
To do it we use the following code in the WebUserControl's PageLoad:
- if(!IsPostBack){
- hf2_ID_SpidFinanziamento.Value = Request .QueryString["ID_SpidFinanziamento"];
- int ID_SpidFinanziamento = Convert .ToInt32(hf2_ID_SpidFinanziamento.Value);
- RefreshFinanziamentoAttachments(ID_SpidFinanziamento);
- //su page hf_ID_SpidFinanziamentoStato
- string cn;
- foreach (Control c in this.Page.Master.FindControl("cphMiddle").Controls)
- {
- c cn = c.ClientID;
- cn = "" ;
- }
- HiddenField hf = (HiddenField)this.Page.Master.FindControl("cphMiddle").FindControl("hf_ID_SpidFinanziamentoStato");
- hf hf_ID_SpidFinanziamentoStato2.Value = hf.Value;
- }