473,324 Members | 2,567 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,324 software developers and data experts.

protected withevents shadows - how do I use this?

I have several aspx pages that include a couple of asp:placeholder controls,
an example is myPage.aspx.

The page inherits from a custom class 'myClass' which inherits
System.Web.UI.Page which lets me ad my own properties and methods to a bunch
of pages in my app.

I want code in myClass to set the contents of the placeholders in myPage.

If I insert the mark-up <asp:placeholder id="myPlaceholder" runat="server"
/> in myPage.aspx and I declare the placeholders in myClass as Protected
WithEvents myPlaceholder As System.Web.UI.WebControls.PlaceHolder
my application runs fine but...

As soon as I edit anything in Visual Studio it sees the placeholder markup
in the .aspx and generates a corresponding
Protected WithEvents myPlaceholder As System.Web.UI.WebControls.PlaceHolder
in myPage.aspx.vb

This is bad! Now the application won't run because myPlaceholder is declared
twice - once in the page code behind and once in the myClass which it
inherits.

If I delete the declaration from the underlying class the code in that class
can't access the placeholder in the page. So I must delete the
auto-generated lines form the .aspx.vb code to get it to run.

Now, when the offending lines are in place the systax checker highlights the
declaration (in myPage.aspx.vb) as conflicting (with that in myClass.vb) and
says I should be using 'shadows' - but where?

Do I declare the placeholder in myClass as shadowing the one in the page, or
do I declare the one in the page as shadowing the one in myClass? What is
the correct syntax, and will it stop Visual Studio from autogenerating
invalid code?

Brian Lowe
---------@
Nov 19 '05 #1
4 2316
Brian:
One thing you could do is mark myPlaceHolder in myClass as mustimplement and
myclass as mustinherit (abstract in the C# world), I believe this will
solve your problems:

public MustInherit class myClass
inherits Page

protected WithEvents MustImplement myPlaceholder as PlaceHolder
....
end class

and you can leave the myPlaceholder in your page as you normally would
The only down side is that VS.Net doesn't like having abstract classes as
base-pages, so the designer will spit up an error each time you switch to
design mode...you should be fine to just hit "ok" and keep going...sorta
annoying...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Brian Lowe" <br********@ntlworld.com> wrote in message
news:uS**************@TK2MSFTNGP12.phx.gbl...
I have several aspx pages that include a couple of asp:placeholder controls, an example is myPage.aspx.

The page inherits from a custom class 'myClass' which inherits
System.Web.UI.Page which lets me ad my own properties and methods to a bunch of pages in my app.

I want code in myClass to set the contents of the placeholders in myPage.

If I insert the mark-up <asp:placeholder id="myPlaceholder" runat="server"
/> in myPage.aspx and I declare the placeholders in myClass as Protected
WithEvents myPlaceholder As System.Web.UI.WebControls.PlaceHolder
my application runs fine but...

As soon as I edit anything in Visual Studio it sees the placeholder markup
in the .aspx and generates a corresponding
Protected WithEvents myPlaceholder As System.Web.UI.WebControls.PlaceHolder in myPage.aspx.vb

This is bad! Now the application won't run because myPlaceholder is declared twice - once in the page code behind and once in the myClass which it
inherits.

If I delete the declaration from the underlying class the code in that class can't access the placeholder in the page. So I must delete the
auto-generated lines form the .aspx.vb code to get it to run.

Now, when the offending lines are in place the systax checker highlights the declaration (in myPage.aspx.vb) as conflicting (with that in myClass.vb) and says I should be using 'shadows' - but where?

Do I declare the placeholder in myClass as shadowing the one in the page, or do I declare the one in the page as shadowing the one in myClass? What is
the correct syntax, and will it stop Visual Studio from autogenerating
invalid code?

Brian Lowe
---------@

Nov 19 '05 #2
"Karl Seguin" wrote in message
news:u0****************@tk2msftngp13.phx.gbl...
One thing you could do is mark myPlaceHolder in myClass as mustimplement
and
myclass as mustinherit (abstract in the C# world), I believe this will
solve your problems:

public MustInherit class myClass
inherits Page

protected WithEvents MustImplement myPlaceholder as PlaceHolder
...
end class


Thanks for this. I really thoguht it was going to solve my problem. I can
live with the relatively minor annoyance of having to click 'OK' each time I
switch views if it saves me the major annoyance of having to remember to
open up the code-behind and manually delete the offending lines of
auto-generated code.

However, when I change my code to read
Protected WithEvents MustImplement myPlaceholder As
System.Web.UI.WebControls.PlaceHolder
VS comes up with a new warning saying that
'WithEvents' variables must have an 'As' clause.

As far as I can see it *does* have an 'As' clause, so what's VS complaining
of now?

The help for MustImplement shows examples of use which I don't understand...
Public Property MustImplement() As Boolean

This doesn't seem to refer to any control, but adds a MustImplement Boolean
property to he MustInherit class. How do I apply this to my placeholder
controls?

Brian Lowe
---------@
Nov 19 '05 #3
"Karl Seguin" wrote in message
news:u0****************@tk2msftngp13.phx.gbl...
The only down side is that VS.Net doesn't like having abstract classes as
base-pages, so the designer will spit up an error each time you switch to
design mode...you should be fine to just hit "ok" and keep going...sorta
annoying...


Not just anoying... if I make myClass abstract then after I click 'OL' in
the warning dialog I get the HTML view of the page with no option to view
the page in designer mode.

This may not be a bad thing... It's the switch from designer to HTML modes
that triggers the autogeneration of the bad code, so using an abstract and
losing the designer mode will indirectly solve the problem, but I'd rather
solve it properly.

Brian Lowe
---------@
Nov 19 '05 #4
I'm being a vb.net idiot but give a c# guy a break...

it's MustOverride and it'll only work on properties, so you'll have to
change things around a bit:

public class mustinherit myclass
protected MustOverride ReadOnly myPlaceholderProperty () As Placeholder

...
end class

public class page
inherits myclass

protected myPlaceHolder as PlaceHolder

protected ReadOnly myPlaceholderProperty as Placeholder
get
return myPlaceHolder
end get
end property
end class
try that on for size :)
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Brian Lowe" <br********@ntlworld.com> wrote in message
news:eq*************@TK2MSFTNGP15.phx.gbl...
"Karl Seguin" wrote in message
news:u0****************@tk2msftngp13.phx.gbl...
One thing you could do is mark myPlaceHolder in myClass as mustimplement
and
myclass as mustinherit (abstract in the C# world), I believe this will
solve your problems:

public MustInherit class myClass
inherits Page

protected WithEvents MustImplement myPlaceholder as PlaceHolder
...
end class


Thanks for this. I really thoguht it was going to solve my problem. I can
live with the relatively minor annoyance of having to click 'OK' each time
I switch views if it saves me the major annoyance of having to remember to
open up the code-behind and manually delete the offending lines of
auto-generated code.

However, when I change my code to read
Protected WithEvents MustImplement myPlaceholder As
System.Web.UI.WebControls.PlaceHolder
VS comes up with a new warning saying that
'WithEvents' variables must have an 'As' clause.

As far as I can see it *does* have an 'As' clause, so what's VS
complaining of now?

The help for MustImplement shows examples of use which I don't
understand...
Public Property MustImplement() As Boolean

This doesn't seem to refer to any control, but adds a MustImplement
Boolean property to he MustInherit class. How do I apply this to my
placeholder controls?

Brian Lowe
---------@

Nov 19 '05 #5

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

Similar topics

4
by: Tee | last post by:
Hi, I am converting a code from VB to C#. in VB, it's Private WithEvents MyButton As Button what's the code in C# ? I can't get the replacement for the "WithEvents" in C#.
2
by: Andreas Klemt | last post by:
Hello, what is the difference between a) Protected WithEvents myClassName b) Protected myClassName Thanks, Andreas
2
by: Benign Vanilla | last post by:
I am a ASP.NET newbie so please bear with me. I had a series of webforms working on my web site, and then I made some tragic error that is causing all kinds of problems. The main symptom is that...
0
by: hansiman | last post by:
I sometimes see references to controls that has been removed from the aspx page in the code behind. The references linger in the region "Web Form Designer Generated Code" and look like Protected...
7
by: Mike Voissem | last post by:
Every time I change a web user control(place a new object on it, or just change an objects properties), all of my Public WithEvents change to Protected WithEvents. Anyone have an idea of why this...
7
by: Satish | last post by:
Hi Friends I am little confused about the shadows keyword in VB.NET could anyone explain with an example about Shadows keyword Many thanks Satish
3
by: flat_ross | last post by:
For anyone who is just getting into VB.NET and/or is starting to work with inheritance I would like to point out a potential pitfall. We found this confusion recently when code-reviewing an...
4
by: dbuchanan | last post by:
Is the following behavior normal? Both the 'Protected sub' in the inherited form and the 'Private Shadows sub' in the derived form fires. My interpretation of MSDN help on the topic "Shadows"...
2
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
In the class below, I inherit from Generic.Dictionary so I can override property Item. Item is not overridable, so I used Shadows, and it works as I want. It works equally well if I replace...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: 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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.