Find Controls in asp.net with and with out Master Page

 In ASP.NET application with a MasterPage, all the controls receive a prefix such as “ctl00$<ContentPlaceHolderID>$<Control ID>”  to their names according to their place in the page hierarchy. That is done in order to prevent from two controls to have the same ID on the same page.
We encounter a problem whenever we want to seek a control. Lets assume we have a page with a control named “LoginButton”. Normally we would use the following command:

this.Page.FindControl("LoginButton") This will work only if we don’t have a MasterPage present. If a master page is present we must add the prefix in order for this to work, so the line will look like this:

this.Page.Master.FindControl("ctl00$ContentPlaceHolder1$LoginButton")

That will also work. But we don’t want to see hard coded strings like “ctl00$ContentPlaceHolder1″ because if tomorrow we will change the hierarchy of the page, change names or something like that, everything will fall apart.

There is a nice way to make this more robust and simple to maintain. My solution is to save a variable that holds a reference to the closest ContentPlaceHolder. The rational is that a Page does not need to know its place in the hierarchy of pages in the application, but it should know the closest ContentPlaceHolder above it.

just use the below code use

((Button)this.Page.Form.FindControl("ContentPlaceHolder1").FindControl("LoginButton"));

find master page control in content page

((Button)this.Master.FindControl("ContentPlaceHolder1").FindControl("LoginButton"));