I did manage to get this working with some extra lines.
So the final code was to first find Contentplaceholder in my top master, then search for the Contentplaceholder in my nested Masterpage and finaly search for the textbox. It works, but when debugging i can see that there are some other isues with the code where in some cases the textbox is'nt found. I'm going back to my previusly working code where i access all the controls directly and not with findcontrol. But if someone is intrested this worked (almost) for me:
My Top Masterpage (Site.Master)
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="mysite.SiteMaster" %>
<html>
<head>
// MasterPage head stuff
// ...
</head>
<body>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
// My contentpages that use only the top masterpage
// My contentpage contacts.aspx begin here, This is in a separate file called contacts.aspx.
// In code the contentpage is theoretically here, when the site runns it works in another way. Here things are explained; http://odetocode.com/articles/450.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="contacts.aspx.cs" Inherits="mysite.contacts" %>
<asp:Content ID="contactsContent" ContentPlaceHolderID="MainContent" runat="server">
// Here is the content of a contentpage (contacts.aspx) that use the Site.Master
</asp:Content>
// contentpage contacts.aspx end here
</asp:ContentPlaceHolder>
</body>
</html>
My Nested Masterpage (XYZ.master)
<%@ Master Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="XYZMasterPage.master.cs" Inherits="mysite.XYZ.XYZMasterPage" %>
<asp:Content ID="NestedMasterPageContentPlaceHolder" ContentPlaceHolderID="MainContent" runat="server">
Nested MasterPage stuff
...
<asp:ContentPlaceHolder ID="NestedMainContent" runat="server">
// Here is my contentpage where textbox1, 2, 3 etc. is
// Here is the content of a contentpage (batch.aspx) that use the nested masterpage XYZMasterPage.master
<%@ Page Title="" Language="C#" MasterPageFile="~/XYZMasterPage.master" AutoEventWireup="true" CodeBehind="batch.aspx.cs" Inherits="mysite.XYZ.batch" %>
<asp:Content ID="batchInvContent" ContentPlaceHolderID="NestedMainContent" runat="server">
// Here is the content of a contentpage (batch.aspx)
<asp:Panel ID="PanelBatch" Runat="Server" >
<asp:TextBox runat="server" ID="ArticleNr1" />
<asp:TextBox runat="server" ID="ArticleNr2" />
<asp:TextBox runat="server" ID="ArticleNr3" />
<asp:TextBox runat="server" ID="ArticleNr4" />
<asp:TextBox runat="server" ID="ArticleNr5" />
<asp:Button runat="server" ID="buttSubmit" OnClick="buttSubmit_Click" />
</asp:Panel>
</asp:Content>
// contentpage batch.aspx end here
</asp:ContentPlaceHolder>
My codebehindfile for batch.aspx
protected void buttSubmit_Click(object sender, EventArgs e)
{
ContentPlaceHolder parentCP = this.Master.Master.FindControl("MainContent") as ContentPlaceHolder;
ContentPlaceHolder childCP = parentCP.FindControl("NestedMainContent") as ContentPlaceHolder;
string strTextbox = string.Empty;
for (int i = 1; i < 6; i++)
{
strTextbox = "ArticleNr" + i.ToString();
TextBox txt = childCP.FindControl(strTextbox) as TextBox;
if (txt != null && !string.IsNullOrEmpty(txt.Text))
{
// ...
// Insert to db
// ...
}
}
}