Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

user control

Status
Not open for further replies.

HrvojeVd

Programmer
Jun 22, 2008
36
0
0
HR
I created a login user control.
When I call it from master page and when a button is clicked on user control I want to get value of user name from user control textbox and put it into textbox in master page?
 
Technically speaking the user control shouldn't be dependent on a control that is not contained within it.

You could bind an event on the masterpage to the user control button click (exposed through a public property), and then get the masterpage to do what you want in the event handler.
 
You have to expose a public property on the masterpage as niceguy says. Then on the button click in the UC, you can grab the value in the tb and set the masterpage's property with that value. Then set the tb on the masterpage with the value from the property.
 
The problem is that my user control is in a folder and I'm calling it with show method in master page.
I can't get a reference to master page.
 
user control is in a folder
this doesn't matter at the point you are referencing objects it's just OOP.

You can reference the master page from the webform.
MyMaster blah = (MyMaster)this.Master;

from a user control you can reference the master from the page
MyMaster blah = (MyMaster)this.Page.Master;

However this breaks the concepts of encapsulation and loose coupling.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
I tried to use that code to reference my master page but it doesn't work. I can't get to public property from my master page.
 
and you casted the Page.Master to your Master page type? That's worked for me in the past. Does the page (aspx) file have a reference to the explicit master type in the page declaration? something like
Code:
<%@Page ... MasterType="MyMaster"%>
or something like that, it's been a while since I messed with webforms.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top