calling a master page's method from user control

Hey all,

 I have a user control on an aspx page which has a master page. That master page has a method, which I need to call from the user control's button click event. How can i access master page's method from a user control which is used on an aspx page?

 Thanks,

Ujjaval
 

0
ujjaval
12/8/2006 6:40:11 AM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

2 Replies
1346 Views

Similar Articles

[PageSpeed] 16

One way of doing this is as follows:

1. Define an interface in your App_Code folder, and on this interface define the methods that you want to expose from the Master Page.
2. Have the Master Page implement the interface.
3. In the user control, you can then access the Page.Master property. Cast this to the interface you defined in 1 using trycast (in Visual Basic) or as in C#.
4. If the result of 3 is not null/Nothing, then call the method.

 


Regards

Dave
0
DMW
12/8/2006 9:57:43 AM

Hey Dave,

 That worked just fine. Thanks for your help.

 Ujjaval

0
ujjaval
12/10/2006 12:56:45 PM
Reply:

Similar Artilces:

Calling user control's method from master page???
I have a user control in a master page, when i try to access the controls method from master page  i get Object reference not set to an instance of an object. What am i doing wrong? please help. Many thanks in advance. .. codes for user control and master page is shown below. -- User Control public partial class UC_uc : System.Web.UI.UserControl{public string Name{get { return txtName.Text; }set { txtName.Text = value; }} public event EventHandler OnSearch;protected void Page_Load(object sender, EventArgs e){} public void btnSearch_Click(object sender, EventArgs e){OnSea...

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

Can I have a web user control call a method on the page it's parent page?
I'm building an application where I'm using serveral different controls on a page and as one of them causes a postback I may want the page to make changes to other controls.  Is there a way to either fire and event off from the control that the page could then capture or simply have the control call a method of it's parent page? Obviously the Page object is there to work with, but I can't seem to figure out how to specifically cast it as a specific page.  For real man, In your user control you need to create a public event which is raised by the event of the...

Can I hide a user control's control from the hosting page's client script?
Okay, my previous question was not unswered and I guess you can't hide a control's panel with server code then show it with client code. Now this is what I try to do: on the hosting page's onload event, call a function to hide the user control's penal. Here is the deal: the user control was looped as many times as data required. So the penals will be name mypanel1, my panel2, etc... that is not even a problem if I know if the following is true: * Do all server codes finish running before the page get sent back to the client? Say the database gave me 5 penals, I can then determine how many times to call the panels to hide. Yes, all the server code is run before the page is sent back to the client....

Label control's text doesn't appear to be set (in the page which has a user control )when trying to update the text property in the FormView's ItemUpdated event
Hi There,I have a user control which hosts a formview control, gridview control and a label control. The grid view is usedto show rows in the DB and when clicked to edit each row, a form view opens up in edit mode with that particular row info. So I have nothing in the item template.My first question is..is it mandatory to have smth in the itemtemplate of the form view.I have controls in edititemtemplate and insertitemtemplate.When a particular row is edited, I would like to show a status msg showing that the row has been updated.For this, I use the ItemUpdated event of the formview and try ...

Calling a page's event or method in a created User Control
Hello.  I have a userControl that has two buttons; "Save", "Cancel" I placed this UserControl on a webpage.  Everytime a user clicks on one of the buttons, I want it to call a method or event in the web pages *.apsx.cs page.   is this possible?   thanks   Sure. In order to do that you will need to declare public events in your user control. In this control, those public events must be raised on the actual button click events. In your host page (where the user control is placed) you will reference the public events as usercontrol1_Myevent1...

How to a call a function from a user control's parent user control ?
 hiHow to a call a function from a user control's parent user control ? for example i have one user control an tree in user control i add other user control in place holder for add node for tree Now how i can rebind tree when i add new node thank a lot  You can rebind the whole page if you do a Page.DataBind(). Alternatively, if you need to bind only one specific control in the parent, you can create an interface such as IMyParentUserControl, create a method definition within it such as:public interface IMyParentUserControl{     void DoMyBinding();} a...

How could a master page control call a content page's function?
Dear all: For example: 1. In master page, place a button named "button1" . 2. Add three content page, ( add some code )3. Run application, in content page 1, click button1, show "this is page1",  in content page2, click button1, show "this is page2", and so on . Besides, these code should be in every content page instead of in master page, because actually action should be very complex, master can't predict everything. Is this possible?  Thanks!  Here's a great tutorial that may get you started: Creating a Common Toolbar in ASP.NET ...

How to set a Master Page's control's property through content page on a postback event?
Hi all, i m using a master page in my application. i have a panel on master page and a tab container with three tab panels on content page. i want to set/change  the visibility of the panel control when the tab is changed on the content page. By default the panel is invisible. To implement this i executed the following steps: 1. Set AutoPostBack of tacontainer to true 2. Wrote an event handler for ActiveTabIndexChanged event of the tab container 3 Wrote the following code on Tab changed event   if (TabContainerEmpPerformance.ActiveTabIndex == 1) { ...

How to do post back in a dynamically created user control [provided that update panel is in the master page of the page where user control is added] {B/C of FileUpload Control}
I have a register my scriptmanager and place the update panel around contenttempalte for my pages int the master page. Now in one of my pages i am adding some user controls dynamically. In two of my user user controls I have FileUpload control which will not work under partial post back. So I want's full postback for them How could I do that {Provided that i am on the user control,which is inside the page ,and page have the contenttemplat...

passing querystring from user control to master page's content page
Hi all,        I have a master page which contains two linkbuttons. I want that when user clicks first link button then querystring value is passed to content page's Initialize culture method. how can i do this. English | Spanish < - user control link Master page contains this user control Default page's initializeCulture method need to know which link is clicked and then set culture according.  code inside initializeculute is like thisif (Request.QueryString["Culture"] == null) {Culture = "en-US"; } else {Culture = Request.QueryString["Culture"].ToString();Culture = Culture == "ES" ? "es-ES" : "en-US"; } Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Culture); Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(Culture);   how to get this Request.QueryString["Culture"] from user control inside master page ? Please help me with code or links Thanks Please put this code in the master page's mark up code, <asp:HyperLink ID="hlEnglish" NavigateUrl="~/Demo.aspx?Culture=en-US" runat="server">English</asp:HyperLink> | <asp:HyperLink ID="hlSpanish" NavigateUrl="~/Demo.aspx?Culture=es-ES" runat="server">Spanish</asp:HyperLink>and put this code in any pages's code behind,  ...

Master Control
I find Master Page idea brilliante. But wouldn't it be nice to have an ability to assign master layout for user controls? Does anyone know of something like that? Look into Themes and Skins. Skins are user to set a template for a contol.Themes and SkinsThemes and Skins 2 www.hopeasp.net Hmm Sean, themes and skins will only help with STYLING the components not layout. What I need is something to set the LAYOUT of the user control and use that master layout to place components in. Like in master page but in user controls.Simple example: Master Control fileUsercontrol layout st...

User Control Within UserControl
If I have a user control A and then inside it a user control B embedded/referenced within it.  User Control A has a panel defined (cpeNewUser) that I want to manipulate from the code behind of User Control B based on some event that happens.So putting this in my code behind of User Control B won't work as it has no idea of cpeNewUser:cpeNewUser.Collapsed = true;So is it because only at runtime they are married up and because of this you cannot access each other's objects at compile time?  How would I get this to work becuase I'm using all user controls inside a AJAX Too...

Access parent page's controls from a user control
I have a .ascx user control that contains a button. I place this user control on a .aspx web page. The web page contains a textbox. When I click on the button in the user control I want the data in the textbox (in the web page) to be saved to the database. I want to write this code in the click event of the user control's button. Is there any way I can access the parent web page's controls from the user control? Add event to user control which fires on page when button inside user control is clicked. view post 779045Jigar Desai-----------------------Do not forget to "Mark as Answer...

Calling a method from a control page on the axpx page where the control page exists.
Hello,  I have an .aspx page that has a method called grdMain_DataBind().  I have a control page that loads within the aspx page which has its own logic.  I have a button on my control page called "SAVE".  How can I call the method grdMain_DataBind thats in my aspx logic from the control that exists on that page when I click SAVE button.  Is there a way? If I were you, I'd simply create a "Save" Event within your control. When the Button in your control is pressed, in the Click handler for that Button you can raise the event. Then, within t...

calling Master Page Method from User control
Hi I have a user control placed in one of the content pages under a master page. from userControl, i want to call a method that exist in "master.cs".Can some one help me or pass some code how to handle this? Do delegates work in this scenario?  mk stupid but relavent question.......is it a method or an event?Let the game begin!!Barcode image generation made easy.Writing an ActiveX Control in C#Generating Relational Data From XML Datatype -Part 1Generating Relational Data From XML Datatype -Part 2Dynamic XML From SQL Server I think you just need a reference to the yo...

CS0012 when referencing controls on master page's master page.
 I'm working with a content page that has a master page (we'll call it ChildMaster). ChildMaster also has a master page (ParentMaster). There is a control on ParentMaster I need to access from the content page. The code looks like this:  ControlType controlInstance = (ControlType) Master.Master.FindControl("controlID");  When I upload, I get CS0012 telling me that ParentMaster is defined in an assembly that is not referenced, and I need to add a reference to some assembly with a funky random-looking name (which changes when I reupload ParentMaster). Up t...

Using controls from pages, master pages, and user controls
How would I structure my site in this scenario: I'd like to use a dropdownlist all over my site, sometimes in a regular page, sometimes in a master page, and sometimes in a user control.  I wish to bind its events programmatically, so normally I would just put that in the codebehind.  However, I notice a lot of code duplication because I have to declare the control in everywhere, in my base page (which all my pages inherit from), in my base master page (which all my master pages inherit from) and in my base user control (which all my user controls inherit from).How should I be...

Setting a parent page's label control text from a user control
I have a .net 2.0 site where I'll have the same form for user input on a number of pages. I plan on using a user control for this. The catch is if the user doesn't input the data properly I want to write the error message to a label control on the parent page, not in the user control. This is because the design for each parent page is different enough that we need to display the error message in a different part of the page. I've seen a couple of websites that mention using a base page that all my pages could inherit from to have a user control interact with the parent page. This blog post is one of them. http://blogs.neudesic.com/blogs/jason_jung/archive/2006/09/12/293.aspx Is this really the best way to do this?I'm not familiar with a base page class. Is there any problem with pages inheriting from a custom base page class while at the same time using master pages?Any other thoughts?  You definately could do that.  If you do I would create a ControlBase class that inherits from System.Web.UI.UserControl.Then create your control and replace the base class in each UserControl that you create with ControlBase.Of course, for this to work you would have to name the label on each page the same. Ie.  This would be your ControlBase Class: public class ControlBase : System.Web.UI.UserControl { public Label ParentPageLabel { get { Label lblParentPageLabel = ( Label ) Page.FindControl ( "lblPare...

call method of parent user control on child user control
Hi, Does any1 let know , How to call method of parent user control on child user control actually my parent user control has a button .... and i wnt to call button click event of parent user control at child user control . Its Urgent plzz. Thanks, Mohit  In your parent UserControl, expose a public method.  Then in the child user control, cast Parent as the parent UserControl's type and call the method. (Parent as ParentUserControlType).MyPublicMethod();  "You shall love the LORD your God with all your heart and with all your soul and with all your might." - GOD...

Master page's User Controls do NOT grey out for the ModalPopupExtender
I use a ModalPopupExtender inside a user control that is placed in a content page, when it popup, the background would grey out EXCEPT the user controls on the master page. Those user controls are still clickable/accessible. Can anyone point out why is that?  Thanks, ~MMJ...

Aspx page to trigger a User Control's methods
i got a user control uc.ascx and loading it in my Page.aspx 's page load event. it works fine! Now i want to call  Sub add()  which is defined in uc.ascx code behind page , from my Page.aspx's btn_click( sender e .....)  event handler... it gives error that wrong refrence to instance of object! Can someone help me out ! First give the access specifier of Sub add() as Public........ Now create an object of the user control in the parent page... The object name should be same as the id of ur usercontrol... For example you havd added a usercontrol uc.ascx into Page.a...

Obtain instance of Main.master from within User Control code behind when user control is referenced from a nested master page
I have a user control that's being referenced from within a nested master page.  I need to FROM WITHING THE USER CONTROL itself (not the other way around, not Master to user control) access a control in the master page because I need to set it's ImageURL.The setup is like this:Main.master (holds a Menu control called Menu1)        Admin.master (inherits Main.master)                   myusercontrol.ascx (is referenced in Admin.master) I cannot figure out how to get an instance to Main.master from within my...

How can I access the property a control on a master page from the master page's code behind.
On my master page I have a label. I want to change this label's text property based on an element of the querystring. (label.text = "NewValue")All child pages using this master will display the same thing so I was trying to put the code in the master page so as not to have to duplicate it for the child pages or put it in a base class and use FindControl.Is it possible to access from a master page's codebehind the property of a server control that is placed on a master page's aspx? If so how?(I saw similar questions, but they all came from the view of a child accessing the property.)Thank you...

Web resources about - calling a master page's method from user control - asp.net.navigation-controls

Resources last updated: 3/25/2016 9:41:43 PM