Is there a difference between these two scenarios:
(1) Access to the resource on the main page from a regular child
(2) Access to the property on the main page from the attached main page
I tried to access the text block on the main page from this page:
TextBox a; a = (TextBox)Master.FindControl("ayyash"); // Master is declared in MasterType directive defaultTextbox.Text = a.Text; // defaultTextBox is a textbox control inside default.aspx
it works, but then when I applied the same method on the nested main page:
TextBox a; a = (TextBox)Master.FindControl("ayyash"); // Master is declared in MasterType directive myTextBox.Text = a.Text; // myTextBox is a textbox control inside child.master
it doesnโt work, am I missing something? I call both codes inside the regulare page_load handler ...
I also noticed that I canโt set the value of the text box inside the nested main page from the code behind, definitely something is missing, what is it? To shed light on this issue, here is an example:
Nested master page:
<%@ Master Language="C#" MasterPageFile="MasterPage.master" AutoEventWireup="false" CodeFile="MasterPage2.master.cs" Inherits="MasterPage2" %> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:textbox id="tx2" runat="server" text="this is two"></asp:textbox> <asp:contentplaceholder id="newstuff" runat="server"></asp:contentplaceholder> </asp:Content>
Code behind:
Response.Wrote(tx2.Text);
I AM NOTHING, why did I miss? note that I also tried recursive search:
String str = ((TextBox)((Content)FindControl("Content2")).FindControl("tx2")).Text;
still nothing
Ayyash
source share