.Net Framework, Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML

Ado.netAsp.Net 2.0SQLC-SharpXMLFrameworkIISXMLWebServiceArchitecture
UMLProject ManagementSDLCMethodologiesDesign PatterenOOPWCF.Net RemotingWWF
MVPMVCSilver LightN-HibernateAjaxJ-QuerySEO-MarketingSite MapPhp

Master page in Asp.net 2.0

Masterpage in Asp.Net 2.0Asp.Net 2.0Session in Asp.Net 2.0
Generic in .Net 2.0Caching in .Net 2.0Async Mailing
Ado.net 2.0Asp.net data controlsAsp.net 3.5 new features


How to Add attribute on Master page body, and access that from an user control is being used under that master page.?
Add attribute in master page body, access from user control
<body runat="server" id="MasterBody" class="MainTable" >
1:
2:In Master page Code behind file
3:
4:public HtmlGenericControl BodyTag
5: {
6: get
7: {
8: return MasterBody;
9: }
10: set
11: {
12: MasterBody = value;
13: }
14: }
15:
16:
17:
18:In user Control Pre render .
19:This is how u can access the master page property from a user control is being used under that master page
20:
21: MasterPage objMaster = this.Page.Master;
22: System.Type t = objMaster.GetType();
23: object bodyObj = (object)t.GetProperty("BodyTag").GetValue(objMaster, null);
24: HtmlGenericControl body = (HtmlGenericControl)bodyObj;
25: body.Attributes.Add("onKeyPress", "return checkKeyCode(event);");
26:
How to access a master page property in user control
protected void Page_PreRender(object sender, EventArgs e)
1: {
2:
3: MasterPage objMaster = this.Page.Master;
4:
5: System.Type t = objMaster.GetType();
6: object userObj = (object)t.GetProperty("objUser").GetValue(objMaster,null) ;
7: PortalUser user = (PortalUser)userObj;
8:
9: if (user.Id == 0)
10: {
11: this.IsLoggedIn = false;
12: }
13: else
14: {
15: this.IsLoggedIn = true;
16: }
17:
18: }
19:
Leave your comment.
Name
Email
Comments
Tell Us1262+5 =

Reduce your Dialy IT Cost, Consult with us
Stay healthy in recession

Advertisement
Sponsored by

Privacy Policy ©2009 ETG Consultancy, All Rights Reserved Terms & Conditions
Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML