Last post May 14, 2010 10:53 AM by atconway
May 03, 2010 05:21 PM|RSquared|LINK
I came across this overloads concept when I was trying to implement the custom filed validator in my application. For example I have a btnsubmit command button on my form in the code behind. The cmdsubmit button is being used to obviously call a function
that saves the data to the database. I was reading an example on hoew to use the custom validator control at
http://www.4guysfromrolla.com/articles/073102-1.aspx. When I created a btnSubmit_Click in the Web form I receeived a message that reads as follows btnSubmit_Click shadows an overloadable member
declared in the base class MyForm. If you want to overload the base method, this method must be declared 'Overloads". What does this all mean regarding Overloads. Any help would be greatly appreciated.
May 03, 2010 06:42 PM|torren|LINK
Can you post us a snippet of the code that has the overide method? Usually .Net isn't picky about overrides.
May 03, 2010 06:56 PM|RSquared|LINK
Sub btnSubmit_Click(sender as Object, e as EventArgs)
If Page.IsValid then
=""red""><i>" & txtPrimeNumber.Text & _
" is, indeed, a good prime number.</i></font>")
Response.Write("<font color=""red""><i>" & txtPrimeNumber.Text & _
" is <b>not</b> a prime number.</i></font>")
May 03, 2010 07:55 PM|torren|LINK
Yes that is the code from the website.
I wanted to see the overloaded code you did for the submit button event.
May 04, 2010 03:29 PM|RSquared|LINK
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
Catch ex As Exception
'TODO: Add logger.log and redirect
May 04, 2010 04:02 PM|torren|LINK
Sorry man you got me stumped.
May 04, 2010 06:27 PM|vcsjones|LINK
Just to ask.. Do you have a method called btnSubmit_Click in a class you are inheriting from, or anywhere else, other than this one?
May 11, 2010 05:44 PM|RSquared|LINK
Yes I do.
May 14, 2010 10:53 AM|atconway|LINK
When I created a btnSubmit_Click in the Web form I received a message that reads as follows btnSubmit_Click shadows an overloadable member declared in the base class MyForm. If you want to overload the base method, this method must be declared 'Overloads".
What does this all mean regarding Overloads.
It means exactly what it states; you are creating a method or event that already is defined with the same name and signature in a parent class. In order to declare its 'independence' of sorts and not use the parent method, you need to add the 'Overrides'
keyword on your method.
If you are not truly intending to overload a method or event from the parent class or are not required to (not marked as 'Must Override') then the easiest thing to do is change the event name from btnSubmit_Click to something unique like btnSubmitInfo_Click.
If you must override the event as part of the control, then I recommend you read the following to better understand these inheritance OO principals:
Overloads and Shadows (VB.NET):
Overrides (Visual Basic):
Overloading Methods in Visual Basic .NET:
Hope this helps!