Web User Control Vs. Server Control Library

 So here's my scenario and I don't know if i should be using a web user control or attempt to make my own server control library. The basic mark-up that i want on the page is a image and label all excompassed in a hyper link. But in the declarative mark up of whatever tag i end up making being able to set properties of that tag. For example drop an instance of my tag on the page and i decide that i want this tag to have image1 and the hyper link to go to page1, and so on for everytime i drop a tag on the page. So sample mark up would be something like.

1    <MyTag:Icon id="tag1" runat="server" Image="Image1" HyperLink="Page1.aspx" Label="Go To Page 1" EnablePostBack="True" />
2    <MyTag:Icon id="tag2" runat="server" Image="Image2" HyperLink="Page2.aspx" Label="Go To Page 2" EnablePostBack="True" />
3    <MyTag:Icon id="tag3" runat="server" Image="Image3" HyperLink="Page3.aspx" Label="Go To Page 3" EnablePostBack="True" />

 

The above control would display as 3 images with labels below the image, and on the click, i would be able to redirect to another page or if i wanted to capture the "onclick" event on the page to have it do something else i could. So really all that i am doing in this control is setting properties of the 2-3 normal asp controls, into one declarative tag. I'll need to do have these all over my website, so i was just wondering if anyone could give me some guidance?

 Thanks!


~The KID

Don't forget to mark my response as ANSWERED if you found it helpful
0
The_ASP_KID
7/23/2008 8:26:07 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

5 Replies
568 Views

Similar Articles

[PageSpeed] 54

 That would definitely be a great candidate for a Custom Control - that way it can reside in a different assembly, and you can use it on future projects as well, and you can put it in the toolbox and drag-n-drop it wherever you want.  For the custom control, you'd just want to add an ImageButton and a hyperlink as child controls, give the custom control properties for the NavigateUrl and ImageUrl and apply the NavigateUrl to both of the child controls and the ImageUrl to the ImageButton.  For a better understanding of how Custom Controls work and how to write one, take a look at this (it's not too hard):

http://msdn.microsoft.com/en-us/library/zt27tfhy.aspx

Hope this helps!


"You shall love the LORD your God with all your heart and with all your soul and with all your might." - GOD
0
dbwinger
7/24/2008 12:24:47 PM

I would use usercontrol, and not custom server control. The reason why is this:
* Its more simple and easy to code
* Easier to maintain and understand


I usually go for usercontrol when i want to have a control that consists of multiple controls and doesn't need special handling. If you want to extend a control, like label, then go for custom control. If you need to make a control that needs special handling or events, go for custom control. If you can use the existing events and abilities of a control, use usercontrol.

0
Deleo
7/24/2008 12:45:52 PM

 I would object, but it's obviously everyone's choice.  A UserControl may be slightly easier to code (although not much once you get used to coding a few Custom Controls).  However, it is definitely not more maintainable.  If you end up using your control in multiple projects, using a UserControl means if you want to make an improvement, you need to make the changes to each project.  If it's a CustomControl in a separate dll, all you need to do is make the changes one place, and refresh the dll in each project's Bin folder.

Also, to clarify, you can add events to a UserControl just as easily as you can to a Custom Control so that's not a reason to choose between the two.

Here's an excerpt from http://support.microsoft.com/kb/893667 that should help clear things up:

FactorsUser controlCustom control
DeploymentDesigned for single-application scenarios

Deployed in the source form (.ascx) along with the source code of the application

If the same control needs to be used in more than one application, it introduces redundancy and maintenance problems
Designed so that it can be used by more than one application

Deployed either in the application's Bin directory or in the global assembly cache

Distributed easily and without problems associated with redundancy and maintenance
CreationCreation is similar to the way Web Forms pages are created; well-suited for rapid application development (RAD)Writing involves lots of code because there is no designer support
ContentA much better choice when you need static content within a fixed layout, for example, when you make headers and footersMore suited for when an application requires dynamic content to be displayed; can be reused across an application, for example, for a data bound table control with dynamic rows
DesignWriting doesn't require much application designing because they are authored at design time and mostly contain static dataWriting from scratch requires a good understanding of the control's life cycle and the order in which events execute, which is normally taken care of in user controls

However I would disagree with the "writing involves lots of code" for this example because it's so simple.  


"You shall love the LORD your God with all your heart and with all your soul and with all your might." - GOD
0
dbwinger
7/24/2008 1:36:33 PM

I was talking in general, about easier coding, since i dont know the total extend of this control, and nothing is as easy at it sounds :p

Anyhow, i agree that custom control can be compiled and easier to maintain due to dll's. But you can also compile a usercontrol into a dll :)

In my experience i often write usercontrols that are "tailored" to the specific project, so reusing the code is not something i often do. I wished i had the time to design all my controls as generic as possible, but thats a luxery :p

about custom controls being easy or hard is totally up to each and everyone to decide, and i would say that almost every programmer would agree that usercontrols are much easier to create than custom controls :) As statet above, "suited for RAD".

 

0
Deleo
7/24/2008 1:52:58 PM

 Thanks everyone for your advice. I think I'll probably try doing both and which ever is easier I'll probably implement.


~The KID

Don't forget to mark my response as ANSWERED if you found it helpful
0
The_ASP_KID
7/28/2008 2:15:22 PM
Reply:

Similar Artilces:

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Server Web User Control or Web Custom Control
Ok, I made a DataGrid I like, stuck it in a Web Control Lib, and then to my toolbar. Now I want to take my nice little control and add it to a greater control, maybe place some buttons around it etc. I could always inherit from it in a new custom control and dynamically add the buttons, but I thought about using a Web User Control. I thought I could easily create a Web User Control, drop on my grid and the buttons on a form, and expose some properties and events, but once I got into it, I got a feeling that this isn't what a Web User Control is for. When designing a control li...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

Single page with multiple user web controls VS Multiple page with specific user web controls
I have a question regarding single page with multiple user web controls vs multiple page with specific user web controls   Option 1: I am of the opinion to have multiple pages with specific user web controls and use an object to store all the information as the user navigates through the application. And finally at the end, read this object and save all the information to the backend database.   Option 2: My respected team member suggests that we have only one page, with all the specific user web controls and not use an object, instead show/hide the user web controls based ...

web controls and web user control
i have a problem in a web form , I have a webform that contains a web user control which in turn contains a html input form ,the web control events don't fire up ,When I click button ,no effect ,I don't know what is the effect of the html form which is in the web user control on the web controls in the web form ?? can any one help me the web control event should be handle in the code behind page, is the event handler for the button you are clicking registered? You can try double clicking the button, should give you the default btn_click event handler in code behind. Also, make ...

Web Form Server Controls Vs. HTML controls
Hi1. What is the difference between Web Form Server controls and HTML controls with runat="server" attribute.e.g. <input type="text" id="mytext" runat="server"> Vs. <asp:TextBox id="mytext" />2. Why we should not use the normal HTML control instead of Server Controls since HTML controls are rendered on client side the performance in using them will be much better that using Web form server controls. Pls. can somebody explain this.- Anand one thing i know. there are much more options for the web controls. and web controls are easier to use than the http controls. for exampl...

Web Server Control Containing another Web Server Control?
I'm building a web server control that needs to include functionality from 3rd party web server control, ASPNetMenu. My web server control needs to render ASPNetMenu at runtime to create a menu. I'd like to do this so that my control's parent ASPX page does not need to register ASPNetMenu or make any configuration changes as this should be done through my web server control. Does anybody have any suggestions on how to do this? Mike - Cache entire web sites at the client and server and keep cache current. Cache just got easier! There are two articles that you would want to be int...

How do you expose an event from a server control within an user control on an web form?
I have a calendar inside of an user control Simple.ascx The user control is sitting on my web form Simple.aspx. How do I access the VisibleMonthChanged event from my web form Simple.aspx? Is it possible? Yes Create Event in usercontrol which fires on page when VisibleMonthChanged event fires on usercontrol. Jigar Desai-----------------------Do not forget to "Mark as Answer" on the post that helped you. Ok, I created the event Public Event MonthChanged() in Simple.ascx.vb. Then I add the follow to Simple.aspx.vb Private Sub Simple_MonthChanged() Si...

Mobile Web Controls vs. Web Controls
I am using VS2003 and I have realized that Mobile Web Controls are very basic and simple. So I saw in a post the way to use Web Controls inside Mobile Web Forms. Since then, I often use Web Controls instead of Mobile Web Controls. I put the Web Control inside a Mobile DeviceSpecific and put this DeviceSpecific inside a Mobile Panel. Why the Mobile Controls are so simple?  Does it happen the same in VS2005 or 2008? And, is it right to use only Web Controls inside Mobile Web Forms? Thanks. xesteban:Why the Mobile Controls are so simple?   They are simple because they suppor...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

Persisting data in a web user control, which contains a list of other web user controls.
 Hi All, I have a control I've created, which can have a number of child controls - also user controls - stored as an ArrayList, which can be added wither a design time or programmatically.My problem is when I add to the list programmatically, it doesn't persist them. So if I add 3 child controls in step 1 of a wizard, with the aim that those three will be visible inside the parent in step 3, what happens is that the parent has no child controls and the item count is 0.Can anyone help? Thanks in advance.Code:Parent Control Markup: <%@ Control Language="C#" Auto...

Web Form and Web User Control
Hello, I have a Web User Control (ascx) that includes a button. This button has an onclick event method. This Web User control is included into a Web Form. (thru LoadControl). However, when I click on the button, the event method is not executed. What should I include in order it works fine? Thanks in advance. GAA. Using Loadcontrol is using dynamic controls and when using dynamic controls you must recreate the same dynamic controls ono postback to econstruct the page control tree. It is best if you do this during the Page PreInit event. How complex are your controls ...

Web control in web control
Hi,There are two simple web user controls A and B, where B contains A. They just display the bunch of text boxes, so I do not need them even in tool pane. They sit in the same project next to web form.I noticed that web user control put on ASPX page does not appear in code behind, but if I create it with protected keyword and name being exactly the same as id it works fine. I can access such a web control from code behind and see the value assigned in IE. The problem is that the same routine does work for my A web control in B. When I assign the value IE, I keep getting null reference. ...

How to access individual controls from a form containing the web user control containing those controls
 Below is a block of code in my .aspx form named default.aspx. In this form I load a web user control. I then add it to a place holder control.(Lines 3 and 4 below) So how do I access the individual controls in my web user control? I want to set the properties on those controls, but I am baffled as to how to access the control. For example I have a text label control named "label3". How do I access this control. Because for example, under certain situations I want to hide that control. ( Label3.Visible = false;)  1    if(!Page.IsPostBack) 2&nb...

Web resources about - Web User Control Vs. Server Control Library - asp.net.web-forms

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

Out-of-control car hits Ballajura pedestrians and puts four teens in hospital
Four teenagers were injured in Ballajura on Saturday night when an out-of-control car careered into them.

With gun control off-limits, politicians want tech sector to fight terror
... very next day, the Senate voted against a measure that would have barred gun sales to people on federal terror watchlists. Another gun-control ...

Obama calls for better gun control, and for tech companies to help fight terrorism
President Barack Obama all but called out encryption in a 15-minute Address to the Nation speech on Sunday night. The President touched on various ...

Trump pushes alternative to gun control after attack
Billionaire hits back against New York Times editorial calling for stronger gun control in wake of San Bernardino massacre

Porsche To Mission E Control: We Are Clear For Launch!
... handling of a Porsche. The contrast seemed to start early cries of the Mission E being the next Tesla [&hellip Porsche To Mission E Control: ...

EU could soon have border controls
EU ministers have agreed to press ahead with plans to suspend the Schengen passport-free travel zone, the FT reports.

Windows 10 vs. OS X: Which gives sys admins more control?
Nearly everything can be managed as if it were a mobile device, using APIs at the operating system for assured reach and consistent implementation ...

Erick Erickson Typifies Conservative Insanity On Gun Control
Even though America is averaging one mass shooting a day, and no matter how many Americans get massacred by automatic weapons, conservatives ...

Obama Calls Gun Control ‘A Matter Of National Security’
Obama Calls Gun Control ‘A Matter Of National Security’

Resources last updated: 12/7/2015 7:30:53 PM