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 handling this?

 

Thanks
 

0
dontmindme
4/6/2007 1:22:57 AM
asp.net.getting-started 91979 articles. 3 followers. Follow

1 Replies
1325 Views

Similar Articles

[PageSpeed] 39

Hi dontmindme,

To me, this sounds like a good reason to create a User Control.  I'm assuming that you only want to use it in this one project.  You can put the drop-down list and binding logic in the User Control and then put the User Control on pages where you need it.

Joe


Free C# Tutorial
0
JMayo
4/6/2007 3:04:32 AM
Reply:

Similar Artilces:

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...

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...

Content controls have to be top-level controls in a content page or a nested master page that references a master page.
Why in the world am I getting this error? The solutions I have seen either don't apply or don't work.  Here is my master page code:<%@ Master Language="C#" AutoEventWireup="false" CodeFile="TechLMSMasters/MainSide.master.cs" Inherits="MainSide" %> <%@ Register TagPrefix="usercontrol" TagName="Search" Src="~/library/uc/Search.ascx" %> <%@ Register TagPrefix="usercontrol" TagName="UserName" Src="~/library/uc/UserNameDisplay.ascx" %><!DOCTYPE html PUBLI...

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

ERROR Content controls have to be top-level controls in a content page or a nested master page that references a master page.
This all used to work until about 5 minutes ago. Did I change something? For some reason I am now getting this error: Content controls have to be top-level controls in a content page or a nested master page that references a master page. What I have:  I have a masterpage inside of a directory. That directory is a first level directory with its own web.config file....The whole thing is protected by the web.config file above it (in the main public directory). That main public directory has a masterpage as well. I am not currently linking the two masterpages together becuase...

Error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.
when I make a directory on my root, and in that directory I put a masterpage and a web form ... I get always an error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.   Does somebody know what the problem is ? Is it possible you can't set a masterpage in a directory ... ?Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) i've founded ... I had to nest my masterpage ...Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) Hi Joeri Pansaerts, I am receiving the same error as the one posted her...

problem using user control in content page or master page
hi friends i am new to this forum.. just now i joined.. my problem is while insert user controls in the master page  or in content .. the control is sitting top of the form.. can anyone help me... i have to place the user control in to the content .. The control is inside the content tag.. but while viewing it in design view or in browser its appearing in the top.. i tried using panels also i cannt.. pls help me how to do that.. its very urgentVMSSanthoshWhen you ask a question, remember to click "mark as answered" when you get a reply which answers your question; this en...

How do I check in the master page if one of the pages is using a user control?
I have an email user control that is being used by a couple of my pages, but I want to check in the master page if that control is being used (so I can set SSL redirects).  feedback.aspx: 1 <%@ Page Language="C#" MasterPageFile="~/alaron.master" AutoEventWireup="true" CodeFile="feedback.aspx.cs" Inherits="feedback" Title="Untitled Page" %> 2 3 <%@ Register src="controls/email.ascx" TagName="email" TagPrefix="uc1" %> 4   how would I check in the 'master.cs' code if this feedback.aspx page is using the 'controls/email.ascx' user control?Thanks in ad...

Need to access a Label Control on the Master Page from a user control attached to a content page
Hello all, I have a master page (say  site.master)  with a status Label in it. I have a content page ( say content.aspx)  that has a user control (say usercontrol.ascx). One of the Button Click Events in the usercontrol.ascx needs to pass on some text onto the status label on the masterpage(LabelStatusMsg) and display it. I have been able to do this directly off a content page (content.aspx) by using the following code (VB)  on the master page <%@ MasterType virtualpath="~/site.master" %> and Dim mpLabel As Label = CType(Master.FindControl("LabelStatusMsg"),...

How can I access a control on a master page from a user control using properties?
Hi, I have a master page which I'm using on my aspx page.  Within this aspx page is a user control and I would like to set a label on my master page using a value from my user control. I can do this using FindControl as shown below but I would like to use properties in my master page. The following code in my user control works perfectly: Label theFormName = (Label)this.Page.Master.FindControl("lblFormName");theFormName.Text = "My Test Form"; However I've been told that using properties is a much better ideas (errors would be picked up at compile time an...

Problem with UpdatePanel in User Control in Master Page beign used by a content page
I have 2 User Controls: A ProductList and a CartSummary (this contains an update panel). I also have a Master Page called Main.master which contains a ContentPlaceholder. The CartSummary is used by Main.master.Default.aspx is built on Main.master and contains ProductList in the ContentPlaceholder. I have exposed the update() method of the UpdatePanel in CartSummary. This means that I can invoke the update method from Main.master How can I make the update() method visible to Default.aspx so that I can update the CartSummary as required ? I have been following the tuto...

Accessing a control inside of a User Control within a master page using jscript
To be more precise, I'm using a master page called Main.Master, i have one web form called default.aspx.  It contains nothing. I use user controls to display everything.  For simplicity sake the user control here will be called newproject.ascx. This user control has several text boxes and a save button.  When the save button is clicked, I want to utilize the OnClientClick event and use javascript to validate the values in all the controls before passing them to sql. The source for the button is as follows: <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btn...

Control of the page and the controls on a page
I am building a web app that has some pages that are public and some that are only available based on subscription. Could someone explain the best way (infrastructure wise) how to control whether a server control is visible or enabledand how to control whether a page is viewable or not based on the user and whether or not the user is logged in (or not). If a user is not logged in I would like some controls to be visible but disabled. I also have to control the URL's in case a person learnsthe URL and tries to type it in. My question is more towards how to do this database wise. I am u...

Image on User control not showing on page using user control.
I have a user control under the folder ~/Common/Controls. The user control has a table. I want to set the table row background. The images for the background are being stored under ~/Common/Images. The page that used the user control is in ~/Front/FrmHome.aspx. Now, if I specify the background as background="../Images/bk.gif", the background shows in the user control but not on the page using the user cintrol as expected. If I specify the background as background="/MyWebProject/Common/Images/arrow1.jpg", it shows fine in the user control but doesn't show up agai...

Web resources about - Using controls from pages, master pages, and user controls - asp.net.getting-started

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Fitness is ‘escalating beyond control'
HEALTH experts are warning parents that obsessive exercise can be linked to life-threatening eating disorders in teens, amid an explosion of ...

Otway fire still out of control but no threat to Falls Festival
Firefighters are battling to contain an out-of-control Great Otway National Park fire ahead of an expected hot and windy weather spike on Christmas ...

Review: Sugr Cube, the cute wooden portable AirPlay speaker with gesture controls
... rarer, pretty ones even rarer and the Sugr Cube goes one step further in its bid to stand out from the crowd: it offers gesture-based control. ...

North Korea's Red Star OS leaves the government in control of computers
... least not by most people's standards. Like China , the socialist state is keen to embrace the power of the internet, but wants to retain control ...

You can control this family’s Christmas lights over the Internet
... Horrible disaster waiting to happen? You be the judge. You've never met Ken or Rebecca-Ellen and you probably never will. But you can control ...

This is how Amazon is taking control of delivery – and taking it away from UPS
As Amazon searches for ways to speed up delivery, the company this year made big strides toward cutting out the middle man and establishing a ...

The 10 Dumbest Gun Control Political Cartoons of 2015
Perhaps not just 2015. Maybe the dumbest of all times . Say, you mean stricter gun control laws will stop terrorism? No one tell the 300+ victims ...

You can control this family's Christmas lights over the internet and the results are mesmerising
... as they see fit. Visitors are greeted with a live webcam of the Fairbanks, Alaska house — pictured above — as well as a bank of controls for ...

Afghan officials: Key district besieged by Taliban still under state control
"Taliban rumors that they have captured the district are not true," says local official trapped for 3 days before government reinforcements arrived ...

Resources last updated: 12/28/2015 11:26:05 AM