Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
{        
    TextBox tb = (TextBox)Master.FindControl("txtEmployee_code");
}


set the properties in master page. call this properties another page, but not working

public TextBox tb
{
get { return txtEmployee_code; }
set { txtEmployee_code = value; }
}
Posted
Updated 31-May-12 6:43am
v4

1. Check whether you have added the mastertype declaration in the page directive.
2. if you want to use set/get the textbox value then instead of doing a findcontrol define a public property in the masterpage for setting and getting it and then call this property from the page.
 
Share this answer
 
Comments
Ehsan yazdani rad 11-Aug-13 14:58pm    
Part 2 is Solution but is not description for problem. Why FindControl not working?
My first guess would be that your control is not actually on the master page but on a nested page. If so, this won't find it. You would need to do something like:
C#
this.Form.FindControl("txtEmployee_code");


You can find more examples and more ideas here (make sure to look at the comments, since they have other options people have tried):
http://csharporcas.blogspot.com/2006/05/master-page-find-control.html[^]
 
Share this answer
 
try TextBox tb = (TextBox)Page.FindControl("txtEmployee_code");
 
Share this answer
 
Comments
2011999 31-May-12 12:27pm    
Not Working
You can do it like this

How to Accessing Master Control(Link Button) from Content pages?[^]

Replace LinkButton to TextBox
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900