Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Monday, March 26, 2012

OK, answered my own question

My base class was implementing an abstract method,
forcing me to declare the whole class as abstract too.
VS.NET didn't like this for some reason, even though when
running the app, it appeared to work fine.

>--Original Message--
>I've got a couple of UserControls that are derived from
a
>common base-class. When I try to open them in the IDE,
>the following error is displayed in a dialog window:
>"The file failed to load in the Web Form designer.
Please
>correct the following error, then load it again: Type
>Abstract"
>This has only just started happening, as I've had the
>inheritance working for a good w or so now. I've no
>idea what I've changed to cause this.
>Please help!
>Ben
>.
>Yes this is the reason. I find this very annoying. The only solution is
to make the method virtual and to remove the abstract from the class.
Does anybody know of a better approach?
____________________
www.bloomfield.as.ro

ok, now it's working. the question is if what i did is correct

I added to the ascx file the following line:
Protected WithEvents cls1 As cls1
where cls1 is the class name of the aspx page and in the
ascx Page_Init i wrote:
cls1 = MyBase.Page
It works fine but - is it the correct way?
Thanks

>--Original Message--
>I have a user control inside an aspx page. I was able to
>create a Public property inside the ascx file and call it
>from the aspx but whatever I do, I can't find the way to
>cause an event from inside the ascx file to call any
>function/sub/property etc. The error I'm getting
>is "Reference to a non-shared member required an object
>reference".
>
>.
>Check out: http://www.openmymind.net/communication/index.html
it takes about communication between a page and a user control including how
to do it via events.
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"comp" <nice_guy@.inter.net.il> wrote in message
news:95ee01c4d348$81edfc20$a601280a@.phx.gbl...
> I added to the ascx file the following line:
> Protected WithEvents cls1 As cls1
> where cls1 is the class name of the aspx page and in the
> ascx Page_Init i wrote:
> cls1 = MyBase.Page
> It works fine but - is it the correct way?
> Thanks
>

Okay to override an ASP.NET page's constructor

See any problem with this code:

Here's my Base page class:

Public Class BasePage
Inherits System.Web.UI.Page

Protected m_NeedAlerts As Boolean

Private Sub Page_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles MyBase.Init
Dim doSomethingWithThis As Boolean = m_NeedAlerts
End Sub

End Class

Now, in order to set m_NeedAlerts in a page that inherits from
BasePage, I need to do this, right?

Partial Class AddCertification
Inherits BasePage

Public Sub New()
MyBase.m_NeedAlerts = True
End Sub
End Class

Is there a problem with overriding the page's constructor? I've never
seen this done in all the code I've seen, so I am a little worried.
Is there a better way to do what I am trying to accomplichslolife,

There is no problem with overriding constructor, as long as you put
MyBase.New as the first statement in it. There are a few ways to achieve what
you need (set up m_NeedAlerts from inherited page):
1 - the one you specified - override constructor and set it there
2- override OnInit method in inherited class, set the variable, and then
call MyBase.OnInit
3 - declare a MustOverride method in the base class that will force setting
the variable and call it from your Page_Init sub of the base class before
examining its value

The advantage of 2 & 3 over 1 would be that you may need to refer to
controls' properties to determine the value of your variable, which are not
available during constructor.

HTH
"slolife" wrote:

Quote:

Originally Posted by

See any problem with this code:
>
Here's my Base page class:
>
Public Class BasePage
Inherits System.Web.UI.Page
>
Protected m_NeedAlerts As Boolean
>
Private Sub Page_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles MyBase.Init
Dim doSomethingWithThis As Boolean = m_NeedAlerts
End Sub
>
End Class
>
Now, in order to set m_NeedAlerts in a page that inherits from
BasePage, I need to do this, right?
>
Partial Class AddCertification
Inherits BasePage
>
Public Sub New()
MyBase.m_NeedAlerts = True
End Sub
End Class
>
Is there a problem with overriding the page's constructor? I've never
seen this done in all the code I've seen, so I am a little worried.
Is there a better way to do what I am trying to accomplich
>
>


That's for the advice Sergey. I went with the constructor for now.

On May 3, 8:49 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@.discussions.microsoft.comwrote :

Quote:

Originally Posted by

slolife,
>
There is no problem with overriding constructor, as long as you put
MyBase.New as the first statement in it. There are a few ways to achieve what
you need (set up m_NeedAlerts from inherited page):
1 - the one you specified - override constructor and set it there
2- override OnInit method in inherited class, set the variable, and then
call MyBase.OnInit
3 - declare a MustOverride method in the base class that will force setting
the variable and call it from your Page_Init sub of the base class before
examining its value
>
The advantage of 2 & 3 over 1 would be that you may need to refer to
controls' properties to determine the value of your variable, which are not
available during constructor.
>
HTH
>
"slolife" wrote:

Quote:

Originally Posted by

See any problem with this code:


>

Quote:

Originally Posted by

Here's my Base page class:


>

Quote:

Originally Posted by

Public Class BasePage
Inherits System.Web.UI.Page


>

Quote:

Originally Posted by

Protected m_NeedAlerts As Boolean


>

Quote:

Originally Posted by

Private Sub Page_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles MyBase.Init
Dim doSomethingWithThis As Boolean = m_NeedAlerts
End Sub


>

Quote:

Originally Posted by

End Class


>

Quote:

Originally Posted by

Now, in order to set m_NeedAlerts in a page that inherits from
BasePage, I need to do this, right?


>

Quote:

Originally Posted by

Partial Class AddCertification
Inherits BasePage


>

Quote:

Originally Posted by

Public Sub New()
MyBase.m_NeedAlerts = True
End Sub
End Class


>

Quote:

Originally Posted by

Is there a problem with overriding the page's constructor? I've never
seen this done in all the code I've seen, so I am a little worried.
Is there a better way to do what I am trying to accomplich

Okay to override an ASP.NET page's constructor

See any problem with this code:
Here's my Base page class:
Public Class BasePage
Inherits System.Web.UI.Page
Protected m_NeedAlerts As Boolean
Private Sub Page_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles MyBase.Init
Dim doSomethingWithThis As Boolean = m_NeedAlerts
End Sub
End Class
Now, in order to set m_NeedAlerts in a page that inherits from
BasePage, I need to do this, right?
Partial Class AddCertification
Inherits BasePage
Public Sub New()
MyBase.m_NeedAlerts = True
End Sub
End Class
Is there a problem with overriding the page's constructor? I've never
seen this done in all the code I've seen, so I am a little worried.
Is there a better way to do what I am trying to accomplichslolife,
There is no problem with overriding constructor, as long as you put
MyBase.New as the first statement in it. There are a few ways to achieve wha
t
you need (set up m_NeedAlerts from inherited page):
1 - the one you specified - override constructor and set it there
2- override OnInit method in inherited class, set the variable, and then
call MyBase.OnInit
3 - declare a MustOverride method in the base class that will force setting
the variable and call it from your Page_Init sub of the base class before
examining its value
The advantage of 2 & 3 over 1 would be that you may need to refer to
controls' properties to determine the value of your variable, which are not
available during constructor.
HTH
"slolife" wrote:

> See any problem with this code:
> Here's my Base page class:
> Public Class BasePage
> Inherits System.Web.UI.Page
> Protected m_NeedAlerts As Boolean
> Private Sub Page_Init(ByVal sender As Object, ByVal e As
> EventArgs) Handles MyBase.Init
> Dim doSomethingWithThis As Boolean = m_NeedAlerts
> End Sub
> End Class
> Now, in order to set m_NeedAlerts in a page that inherits from
> BasePage, I need to do this, right?
> Partial Class AddCertification
> Inherits BasePage
> Public Sub New()
> MyBase.m_NeedAlerts = True
> End Sub
> End Class
> Is there a problem with overriding the page's constructor? I've never
> seen this done in all the code I've seen, so I am a little worried.
> Is there a better way to do what I am trying to accomplich
>
That's for the advice Sergey. I went with the constructor for now.
On May 3, 8:49 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@.discussions.microsoft.com> wrote:
> slolife,
> There is no problem with overriding constructor, as long as you put
> MyBase.New as the first statement in it. There are a few ways to achieve w
hat
> you need (set up m_NeedAlerts from inherited page):
> 1 - the one you specified - override constructor and set it there
> 2- override OnInit method in inherited class, set the variable, and then
> call MyBase.OnInit
> 3 - declare a MustOverride method in the base class that will force settin
g
> the variable and call it from your Page_Init sub of the base class before
> examining its value
> The advantage of 2 & 3 over 1 would be that you may need to refer to
> controls' properties to determine the value of your variable, which are no
t
> available during constructor.
> HTH
> "slolife" wrote:
>
>
>
>
>
>
>
>
>