?
Solved

Deriving Web Server control

Posted on 2003-03-24
17
Medium Priority
?
256 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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

615 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