473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.WebControls
Imports System.Globalization

Public Class Test1
Inherits RadioButton
Implements IPostBackDataHandler

Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection ) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData

End Function

Public Sub RaisePostDataChangedEvent() Implements System.Web.UI.IPostBackDataHandler.RaisePostDataCh angedEvent

End Sub
End Class

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

when i compiling this class it gives me error

" Interface 'System.Web.UI.IPostBackDataHandler' is already implemented by base class 'System.Web.UI.WebControls.RadioButton'."

Please help me in this regard

Thanks
Owais

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 21 '05 #1
5 5810
"owais" <sohail29@-NOSPAM-hotmail.com> wrote in message
news:uS*************@TK2MSFTNGP15.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.IPostBackDataHandler' is already implemented by
base class 'System.Web.UI.WebControls.RadioButton'."


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.DoSomething
'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.WebControls
Imports System.Globalization

Public Class Test1
Inherits RadioButton

Public Overrides Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection ) As Boolean

End Function

Public Overrides Sub RaisePostDataChangedEvent()

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 'RaisePostDataChangedEvent' 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(ByVal postDataKey As
String, ByVal postCollection As
System.Collections.Specialized.NameValueCollection ) As Boolean

End Function

Public Overridable des Sub RaisePostDataChangedEvent()

End Sub
End Class

Public Class Test2
Inherits Test1

Public Overrides Function LoadPostData(ByVal postDataKey As String,
ByVal postCollection As System.Collections.Specialized.NameValueCollection )
As Boolean

End Function

Public Overrides des Sub RaisePostDataChangedEvent()

End Sub

End Class

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

I made the class according to your instruction

-------------------------------------------------------
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Globalization

Public Class Test1
Inherits RadioButton

Public Overrides Function LoadPostData(ByVal postDataKey As String,
ByVal postCollection As
System.Collections.Specialized.NameValueCollection ) As Boolean

End Function

Public Overrides Sub RaisePostDataChangedEvent()

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 'RaisePostDataChangedEvent' 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**************@TK2MSFTNGP15.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 'RaisePostDataChangedEvent' 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 NameValueCollection _
) As Boolean Implements IPostBackDataHandler.LoadPostData
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}:GroupRadioButton runat=server></{0}:GroupRadioButton>")
public class Test1 : RadioButton, IPostBackDataHandle

public GroupRadioButton() : 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(HtmlTextWriter output

RenderInputTag(output)
private void RenderInputTag(HtmlTextWriter htw

htw.AddAttribute(HtmlTextWriterAttribute.Id, ClientID)
htw.AddAttribute(HtmlTextWriterAttribute.Type, "radio")
htw.AddAttribute(HtmlTextWriterAttribute.Name, GroupName)
htw.AddAttribute(HtmlTextWriterAttribute.Value, Value)
if(Checked
htw.AddAttribute(HtmlTextWriterAttribute.Checked, "checked")
if(!Enabled
htw.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled")

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

if(onClick != null
onClick = String.Empty
onClick += Page.GetPostBackClientEvent(this, String.Empty)
htw.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick)
htw.AddAttribute("language", "javascript")

els

if(onClick != null
htw.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick)
if(AccessKey.Length > 0
htw.AddAttribute(HtmlTextWriterAttribute.Accesskey , AccessKey)
if(TabIndex != 0
htw.AddAttribute(HtmlTextWriterAttribute.Tabindex,
TabIndex.ToString(NumberFormatInfo.InvariantInfo))
htw.RenderBeginTag(HtmlTextWriterTag.Input)
htw.RenderEndTag()
#endregio

#region IPostBackDataHandler Member

void IPostBackDataHandler.RaisePostDataChangedEvent(

OnCheckedChanged(EventArgs.Empty)
bool IPostBackDataHandler.LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection 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
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...
6
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;...
2
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...
0
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...
4
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...
10
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...
7
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'. ...
10
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...
7
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.