CodeVerge.Net Beta
Login Idy
Register Password
  Forgot?
Explore    Item Entry    Members   
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML





Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 5/22/2006 1:00:04 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 6 Views: 8 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
7 Items, 1 Pages 1 |< << Go >> >|
reo
Asp.Net User
How to access a control in master page?5/22/2006 1:00:04 PM

0/0

Hi.

I have a Textbox control in my master page. I want to set the text of the textbox based on events triggered in the child page.

For this, I tried to first find the control using the following code:

TextBox

t3 = new TextBox();
t3 =
this.Master.FindControl("MAINTEXT");

But it throws an error : Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.TextBox'. An explicit conversion exists (are you missing a cast?)

Can anyone help me solving this cast problem?

Your help is appreciated. Thanks.

reo
Asp.Net User
Re: How to access a control in master page?5/22/2006 1:33:18 PM

0/0

Hi Guyz.

I solved it myself.

 Textbox t3 = new TextBox();
t3 = (Textbox)
this.Master.FindControl("MAINTEXT");

This is all what was needed!!!! How silly of me : )

 

mychucky
Asp.Net User
Re: How to access a control in master page?8/15/2006 3:39:04 PM

0/0

Many thanks for listing your solution. I have a similar situation with SqlDataSource control. I will try your solution to see if it works. On a second note, how do I call a method in the master page?
bitmask
Asp.Net User
Re: How to access a control in master page?8/15/2006 9:04:16 PM

0/0

If you define a public method and use the @ MasterType directive, you'll be able to use Master.MethodName();

See: Master Pages: Tips, Tricks, Traps

LudovicoVan
Asp.Net User
Re: How to access a control in master page?8/15/2006 9:59:16 PM

0/0

Btw, please note that you are instanciating a new Textbox before calling FindControl, but that's not needed as FindControl itself returns a reference to a control instance...

I mean, the code would just look like:

   TextBox t3;
   t3 = (TextBox)Master.FindControl("MyTextbox");

or simply (which is equivalent):

   TextBox t3 = (TextBox)Master.FindControl("MyTextbox");

Regards. -LV


Julio P. Di Egidio
Software Analyst / Programmer
http://julio.diegidio.name

(Peace X Love] = [++1)
mychucky
Asp.Net User
Re: How to access a control in master page?8/16/2006 12:46:25 PM

0/0

Thanks! I'll give that a try.
nickh
Asp.Net User
Re: How to access a control in master page?8/18/2006 5:33:11 PM

0/0

You may want to create a base class for the mater page's code behind with the method for accessing the text box and reference that as the master type.   I have seen some problems in batch compilation when referencing the methods and properties exposed directly in code behind.
7 Items, 1 Pages 1 |< << Go >> >|



Search This Site:


Meet Our Sponsors:



Other Resources:

How to Access properties of control in content page - newsgroup.asp-net ... How to Access properties of control in content page, > ROOT > ... master page control as a public property, and then access the property from the content page. ...
How to properly access controls in the Master Page ... of the great new features in ASP.NET 2.0 has been the ability to use master pages to layout the common ... page, a master page is just a web user control. ...
ASP 2.0: How to access Master Page from Web User Control on Page? master page and in the content section has the control " ... How can I access the Master Page's public. properties/methods from a web user control on the page? ...
Page 3 - How to Use Master Pages (Conclusion) How to access master page controls from a content page ... A content page can access a control in the master page if you expose the control ...
ASP.NET master pages This chapter from Murach's ASP.NET 3.5 Web Programming with VB 2008 shows you how to use master pages to create web pages that have common elements such as banners ...
MS Access How-to Articles ACC2000 How to Change the Caption of a Control on a Data Access Page (Q207744) ... ACC2000 How to Find Out If a Replica Is the Design Master (Q210224) ...
ASP.NET - How to use master pages How to expose a master page control as a public property. 90. How to access a public property of the master page from a content page. 92 ...


 
All Times Are GMT