473,547 Members | 2,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I Implements Parent class Interface in child class

Hi,

I have a problem, I want to implements Parent class interface methods in child class. for e.g

-------------- Test1.vb ----------------
Imports System
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Globaliz ation

Public Class Test1
Inherits RadioButton
Implements IPostBackDataHa ndler

Public Function LoadPostData(By Val postDataKey As String, ByVal postCollection As System.Collecti ons.Specialized .NameValueColle ction) As Boolean Implements System.Web.UI.I PostBackDataHan dler.LoadPostDa ta

End Function

Public Sub RaisePostDataCh angedEvent() Implements System.Web.UI.I PostBackDataHan dler.RaisePostD ataChangedEvent

End Sub
End Class

-------------------------------------------------

when i compiling this class it gives me error

" Interface 'System.Web.UI. IPostBackDataHa ndler' is already implemented by base class 'System.Web.UI. WebControls.Rad ioButton'."

Please help me in this regard

Thanks
Owais

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 21 '05 #1
5 5824
"owais" <sohail29@-NOSPAM-hotmail.com> wrote in message
news:uS******** *****@TK2MSFTNG P15.phx.gbl...
Hi,

I have a problem, I want to implements Parent class interface methods in
child class. for e.g
<snip> " Interface 'System.Web.UI. IPostBackDataHa ndler' is already implemented by
base class 'System.Web.UI. WebControls.Rad ioButton'."


Just take the implements keyword out of your derived class, and override the
methods in the base class that you want your class to handle.
You do not need the implements keyword in your overriding methods either.

eg:

public Class MyBase
implements SomeInterface

protected overridable sub DoSomething implements
SomeInterface.D oSomething
'do whatever
end sub

end class

public class MyDerived
inherits MyBase

protected overrides sub DoSomething
'do something else instead
end sub

end class
hope this helps

Steve

Nov 21 '05 #2
Thanks for the reply.

I made the class according to your instruction

-------------------------------------------------------
Imports System
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Globaliz ation

Public Class Test1
Inherits RadioButton

Public Overrides Function LoadPostData(By Val postDataKey As String, ByVal postCollection As System.Collecti ons.Specialized .NameValueColle ction) As Boolean

End Function

Public Overrides Sub RaisePostDataCh angedEvent()

End Sub
End Class
-------------------------------------------------------------

but unfortunately it also gives me the error

"function 'LoadPostData' cannot be declared 'Overrides' because it does not override a function in a base class.
sub 'RaisePostDataC hangedEvent' cannot be declared 'Overrides' because it does not override a sub in a base class."
Thanks
Owais

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 21 '05 #3
I think in this instance you should declare those methods Overridable and
then in a derived class (child class as you say), you "overrides" the
methods, so:

Public Class Test1
Inherits RadioButton

Public Overridable Function LoadPostData(By Val postDataKey As
String, ByVal postCollection As
System.Collecti ons.Specialized .NameValueColle ction) As Boolean

End Function

Public Overridable des Sub RaisePostDataCh angedEvent()

End Sub
End Class

Public Class Test2
Inherits Test1

Public Overrides Function LoadPostData(By Val postDataKey As String,
ByVal postCollection As System.Collecti ons.Specialized .NameValueColle ction)
As Boolean

End Function

Public Overrides des Sub RaisePostDataCh angedEvent()

End Sub

End Class

"owais" <sohail29@-NOSPAM-hotmail.com> wrote in message
news:eZ******** ******@TK2MSFTN GP15.phx.gbl...
Thanks for the reply.

I made the class according to your instruction

-------------------------------------------------------
Imports System
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Globaliz ation

Public Class Test1
Inherits RadioButton

Public Overrides Function LoadPostData(By Val postDataKey As String,
ByVal postCollection As
System.Collecti ons.Specialized .NameValueColle ction) As Boolean

End Function

Public Overrides Sub RaisePostDataCh angedEvent()

End Sub
End Class
-------------------------------------------------------------

but unfortunately it also gives me the error

"function 'LoadPostData' cannot be declared 'Overrides' because it does
not override a function in a base class.
sub 'RaisePostDataC hangedEvent' cannot be declared 'Overrides' because it
does not override a sub in a base class."
Thanks
Owais

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/

Nov 21 '05 #4
"owais" <sohail29@-NOSPAM-hotmail.com> wrote in message
news:eZ******** ******@TK2MSFTN GP15.phx.gbl...
but unfortunately it also gives me the error

"function 'LoadPostData' cannot be declared 'Overrides' because it does
not override a function in a base class.
sub 'RaisePostDataC hangedEvent' cannot be declared 'Overrides' because it
does not override a sub in a base class."


Hi owais

I just had a quick look through the docs. The interface is implemented in
the web checkbox class, which is the parent of the radiobutton.
The function is private though so you cannot override it

From the docs....

This member supports the .NET Framework infrastructure and is not intended
to be used directly from your code.

[Visual Basic]
Private Function LoadPostData( _
ByVal postDataKey As String, _
ByVal postCollection As NameValueCollec tion _
) As Boolean Implements IPostBackDataHa ndler.LoadPostD ata
Steve


Nov 21 '05 #5
Thanks for the reply. Its amazing ,this code works on C#. I don't know VB.NET and C# both are using same CLR. The code of C# belo

-----------------------------------------------------------

[ToolboxData("<{ 0}:GroupRadioBu tton runat=server></{0}:GroupRadioB utton>")
public class Test1 : RadioButton, IPostBackDataHa ndle

public GroupRadioButto n() : base(

#region Propertie

private string Valu

ge

string val = Attributes["value"]
if(val == null
val = UniqueID
els
val = UniqueID + "_" + val
return val

#endregio

#region Renderin

protected override void Render(HtmlText Writer output

RenderInputTag( output)
private void RenderInputTag( HtmlTextWriter htw

htw.AddAttribut e(HtmlTextWrite rAttribute.Id, ClientID)
htw.AddAttribut e(HtmlTextWrite rAttribute.Type , "radio")
htw.AddAttribut e(HtmlTextWrite rAttribute.Name , GroupName)
htw.AddAttribut e(HtmlTextWrite rAttribute.Valu e, Value)
if(Checked
htw.AddAttribut e(HtmlTextWrite rAttribute.Chec ked, "checked")
if(!Enabled
htw.AddAttribut e(HtmlTextWrite rAttribute.Disa bled, "disabled")

string onClick = Attributes["onclick"]
if(AutoPostBack

if(onClick != null
onClick = String.Empty
onClick += Page.GetPostBac kClientEvent(th is, String.Empty)
htw.AddAttribut e(HtmlTextWrite rAttribute.Oncl ick, onClick)
htw.AddAttribut e("language", "javascript ")

els

if(onClick != null
htw.AddAttribut e(HtmlTextWrite rAttribute.Oncl ick, onClick)
if(AccessKey.Le ngth > 0
htw.AddAttribut e(HtmlTextWrite rAttribute.Acce sskey, AccessKey)
if(TabIndex != 0
htw.AddAttribut e(HtmlTextWrite rAttribute.Tabi ndex,
TabIndex.ToStri ng(NumberFormat Info.InvariantI nfo))
htw.RenderBegin Tag(HtmlTextWri terTag.Input)
htw.RenderEndTa g()
#endregio

#region IPostBackDataHa ndler Member

void IPostBackDataHa ndler.RaisePost DataChangedEven t(

OnCheckedChange d(EventArgs.Emp ty)
bool IPostBackDataHa ndler.LoadPostD ata(string postDataKey,
System.Collecti ons.Specialized .NameValueColle ction postCollection

bool result = false
string value = postCollection[GroupName]
if((value != null) && (value == Value)

if(!Checked

Checked = true
result = true
els

if(Checked
Checked = false

return result
#endregio
}

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2651
by: Suzanne Vogel | last post by:
Hi, I've been trying to write a function to test whether one class is derived from another class. I am given only id's of the two classes. Therefore, direct use of template methods is not an option. Let's call the id of a class "cid" (for "class id"). The function signature should look like this:...
6
10963
by: jalkadir | last post by:
Let's say that I have this class: class Parent{ private: char* str; public: const char* getStr(){return str;} }; And then I create a child class class Child{ private: std::string str; public: std::string& getStr(){return str;}
2
4842
by: Kelmen Wong | last post by:
how to work out a design to enable a child object to call its parent(creator/container) method/property? Its easy to be done if the child can know/assume its parent, but in my scenario, many different object can create the same child object, means the child object's parent is dynamic. Event is possible, but I need the process in...
0
1169
by: Maansi Sanghi | last post by:
Hello, (1) I am building a com component with multiple interfaces in .NET Managed VC++ (2) Then use the managed .NET dll in unmanaged code after registering through regasm and getting the tlb file Problem: (A) Everyrthing works fine except that I get a compile time error C2039 while trying to
4
4556
by: Danny Tuppeny | last post by:
Hi all, I've been trying to write some classes, so when I have a parent-child relationship, such as with Folders in my application, I don't have to remember to add a parent reference, as well as adding to the child collection, eg: parent.Children.Add(child); child.Parent = parent;
10
3993
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms,...
7
2019
by: msxkim | last post by:
How to execute functions in the parent class first and then functions in the child class? For example, I have a parent class with functions 'ONE' and 'TWO' and child class has a function 'THREE'. How should I declare classes so that all three functions are executed when child class is called? Class Parent public function ONE 'code end...
10
19584
by: Goran Djuranovic | last post by:
Hi all, Does anyone know how to declare a variable in a class to be accessible ONLY from a classes instantiated within that class? For example: ************* CODE ***************** Public Class Parent '*** HOW TO DECLARE IT *** Dim Age As String = "1/1/2000"
7
1821
by: Darin | last post by:
I have a parent form that has a menu. I then have a child form on the menu. From the child form I need to change the parent form's menu - how can i do that? I tried me.parent.mfavorites, but that doesn't exist (the menu name is mfavorites). Thanks. Darin *** Sent via Developersdex http://www.developersdex.com ***
0
7510
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7437
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7463
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6032
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3493
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1923
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.