Overides

  • Thread starter Thread starter Brian Shannon
  • Start date Start date
B

Brian Shannon

I see code that uses the overrides. I am having a hard time understanding
what it means. Can someone explain or point me somewhere to read on using
Overrides.

A commone one I see is Overriding the Base page class.

Thanks
 
If your class inherits from a Base Class it can use it's methods.
However if you should want to change the method that the base class already
has defined for use in your child class then you can sign it with overrides.
When you call this method on the child class it will not use the method in
the base as it overridden in the child class.

Typical example if your baseclass had a function to add 5 to an integer but
your child class needed to add ten, you could override the base class
function in your child class.

In Child Class***

Overrides Function CalculateSomething(val as Int32) as int32

return val+10

end function

***In BaseClass

Overrides Function CalculateSomething(val as Int32) as int32

return val+5

end function
 
Hi Brian,

It's probably most helpful to give you an example. Suppose you have an
ASP.NET page that uses a DataGrid. You have users who complain that when
they are editing fields in the DataGrid, the page takes a very long time to
download. You determine that the cause of this is a very large Viewstate
for the page, but you don't want to turn off Viewstate because your
application relies on it.

In that scenario, you might want to continue to use Viewstate but alter the
way that it works. You could write your own class to maintain state, but
that would be a considerable amount of work and it would not be time
well-spent. After all, ASP.NET already provides all the functionality you
need. You just want to tweak it a bit so that it doesn't load the page
down with all of that Viewstate data. You decide that instead of ASP.NET
sticking all of that Viewstate data in a hidden form field, you want to
make it store it in a Session variable. That's the only change you want to
make. All of the other functionality will remain the same.

There are two methods that are used for Viewstate;
LoadPageStateFromPersistenceMedium (loads Viewstate) and
SavePageStateToPersistenceMedium (saves Viewstate). (You can find
information on both in the SDK help.) If you want to modify the behavior
of Viewstate, you can override both of these functions by doing this:

protected override object LoadPageStateFromPersistenceMedium()
{
return Session["_ViewState"];
}

protected override void SavePageStateToPersistenceMedium(object viewState)
{
Session["_ViewState"] = viewState;
}


In this case, you are telling ASP.NET to use your functionality instead of
the code that the developers of ASP.NET wrote into these functions.

Hope that helps.

Jim Cheshire [MSFT]
MCP+I, MCSE, MCSD, MCDBA
Microsoft Developer Support
(e-mail address removed)

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
 
Back
Top