?
Solved

Deriving Web Server control

Posted on 2003-03-24
17
Medium Priority
?
255 Views
Last Modified: 2010-04-15
I want to create my custom button control derived from  System.Web.UI.WebControls.Button ( Like in O'Reilly book Count button ). So far so good.
I don't create separate namespace for it - I create it in the same namespace where my project is ( let's call it ISD ).
I can't deploy it anyhow on another page since I don't know how to register it on page ( I have no aspx file because it derived from Button ).
Seems I do something wrong - help me with issue, please.
0
Comment
Question by:LazyStudent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 5
17 Comments
 
LVL 14

Expert Comment

by:AvonWyss
ID: 8195275
You have to insert the button into an ASPX file. In that ASPX file, you can use the @ Register directive to tell the compiler what allows you to assign your control a tagprefix to access it.

Check the help file unter the index entry "@ Register", and under "custom server controls", "Custom Control Server Snytax".
0
 
LVL 5

Author Comment

by:LazyStudent
ID: 8195353
But System.Web.UI.WebControls.Button has implementation - it is system class. Why I need one more implementation for it?
0
 
LVL 5

Author Comment

by:LazyStudent
ID: 8195514
BTW I did what you adviced -
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: 'isd2.TopMenuBtn' is not a valid base class because it does not extend class 'System.Web.UI.UserControl'.

Source Error:


Line 1:  <%@ Control Language="c#" AutoEventWireup="false" Codebehind="TopMenuBtn.cs" Inherits="isd2.TopMenuBtn" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

Source File: c:\inetpub\wwwroot\isd2\TopMenuBtn.ascx    Line: 1
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:AvonWyss
ID: 8195530
Not implementation, but instance.

If you know what a fax machine is (=definition) and where you can find one (=implementation), it does not mean that you actually have one. To use it, you therefore need to get one (=instance).

You just have to make an ASPX file which uses your button (that is, creates an instance). To be able to specify your control name properly in the ASPX file, you need to use the directives I wrote so that you can tell the ASPX compiler where to find your control.
0
 
LVL 5

Author Comment

by:LazyStudent
ID: 8196097
what about error I stated?
0
 
LVL 1

Accepted Solution

by:
Commodus2 earned 500 total points
ID: 8196269
You can try to make a web custom control instead of a web user control. In this way you only have a .cs file. No ascx needed. Then you can insert it into a aspx file

I made a customize dropdownlist and also created it in the same namespace:

<%@ Register Tagprefix="custom" Namespace="YourCurrentNameSpace" Assembly="YourCurrentNameSpace" %>


...
...
...

<custom:customdroplist id="ddlEquipType" runat="server" cssclass="textbox" height="232px" width="252px"></custom:customdroplist>

this only consists outof a .cs file (web custom control).
Mayby this is of some help
0
 
LVL 1

Expert Comment

by:Commodus2
ID: 8196282
And the decleration in the aspx.cs file ofcourse:

protected TOS.CustomDropList ddlEquipType;
0
 
LVL 1

Expert Comment

by:Commodus2
ID: 8196304
If you make a web user control, you don't need to derive from UserControl. But you'll need to dirive from WebControl since a button is in this lib.

public class CustomDropList : WebControl {
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 8196348
Sorry LazyStudent, I didn't see your error message until now because I was writing the answer when you posted it.

Anyways, just as the compiler says, the control has to be derived from UserControl if you want to use an ASCX file. Otherwise, if you only use a CS file, this restriction does not apply.

Nevertheless, this doesn't make my comment about using @ Register incorrect.
0
 
LVL 5

Author Comment

by:LazyStudent
ID: 8196577
Thank you - it was exactly my problem.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 8197117
Er, didn't I actually answer your question?
0
 
LVL 5

Author Comment

by:LazyStudent
ID: 8201905
I got from Commodus2 exact instructions how to create and register control. I am dumb a lot in .NET so his comments was the best help for me.
If you insist about points I can give you half, but I think Commodus gave a thorough answer for my problem.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 8202252
Don't bother with the points, but please do take note of my following comment.

In your Question, you asked "I can't deploy it anyhow on another page since I don't know how to register it on page ( I have no aspx file because it derived from Button ).". So what I did was to answer to this issue. If that was not your problem at all, you maybe should have asked the question in another way to avoid receiving an answer which was not helpful - and this would also have avoided that I waste time answering the wrong question...

Note that the comment you accepted as answer was a followup to the comments I posted and the error you only posted afterwards. Therefore, it would not have been posted by Commodus2 if he(/she?) had only seen you initial question. The point is, that you accepted a comment as anwer which was not an answer to your initial question, and this in not really motivating for experts such as me who in the first place tried to help with the actual question you posted.
0
 
LVL 1

Expert Comment

by:Commodus2
ID: 8202351
I'm a he... :)

But ok.. I get your point. The only thing i can say about my anwser and the source of it, is that i faced the same problem LazyStudent had. I used the register tag and other stuff from my solution i came up with in the past.
 
I cannot prove that I did not use your comment to make up mine and I know it is very unlikely that you believe me that I did not use it.

The question I understoud was that LazyStudent could not get a control on a aspx page. With this in mind I answered the question. It is true that you said before me to use @register, but i did not use your comments to make mine. I used my previous, self made, solution to answer this question as it was very simular to mine problem.

I do not want to offend anyone here.
0
 
LVL 1

Expert Comment

by:Commodus2
ID: 8202451
I'm a he... :)

But ok.. I get your point. The only thing i can say about my anwser and the source of it, is that i faced the same problem LazyStudent had. I used the register tag and other stuff from my solution i came up with in the past.
 
I cannot prove that I did not use your comment to make up mine and I know it is very unlikely that you believe me that I did not use it.

The question I understoud was that LazyStudent could not get a control on a aspx page. With this in mind I answered the question. It is true that you said before me to use @register, but i did not use your comments to make mine. I used my previous, self made, solution to answer this question as it was very simular to mine problem.

I do not want to offend anyone here.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 8202542
Commodus, you don't offend anyone, and I was not trying to criticize you. It just happens all the time that questioners, when they finally got what they wanted, don't really pay attention on the grading. This then often results in inappropriate point distribution or even bad grades, disappointing the experts who helped.

This is the 6th year that I'm an expert here at EE, and I only try to remind questioners that they must be fair with the experts who handle their questions - experts do not get paid for their work, and it has already made many experts with excellent skills leave because questioners do not care in some way or another. So I'm trying to make questioners more sensible to this issue, hoping that I can contribute a little to the community atmosphere.
0
 
LVL 5

Author Comment

by:LazyStudent
ID: 8202679
Hm... This discussion becomes philosophic issue:-)
i am care to grade the right answer.
my question actually was ".. can't deploy it anyhow on another page since I don't know how to register it on page .." and i expected to get some instructions about that.
AvonWyss actualy told me to RTFM but since i've just started to study i didn't know WHAT i need and HOW to read FM.
commodus gave me exactly what i needed threrefore i choosed his answer.
I realy appreciate experience and valuable time that spend for me but it is strange for 6th year expert not to know that people who can accept answer that he gave do not visit this site - they can find all data they need in google, help or books ( Like i do for applications that i know best ). I consider myself total dummy in .NET so I allow to myself to ask sily questions here and expect for exact instructions like for dummy.

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question