LazyStudent
asked on
Deriving Web Server control
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.
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.
ASKER
But System.Web.UI.WebControls. Button has implementation - it is system class. Why I need one more implementation for it?
ASKER
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\To pMenuBtn.a scx Line: 1
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"
Source File: c:\inetpub\wwwroot\isd2\To
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.
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.
ASKER
what about error I stated?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And the decleration in the aspx.cs file ofcourse:
protected TOS.CustomDropList ddlEquipType;
protected TOS.CustomDropList ddlEquipType;
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 {
public class CustomDropList : WebControl {
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.
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.
ASKER
Thank you - it was exactly my problem.
Er, didn't I actually answer your question?
ASKER
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.
If you insist about points I can give you half, but I think Commodus gave a thorough answer for my problem.
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.
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.
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.
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.
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.
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.
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.
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.
ASKER
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.
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.
Check the help file unter the index entry "@ Register", and under "custom server controls", "Custom Control Server Snytax".