Hi Terry,
For your further questions:
1. Since the ASP.NET's page model is the actual page class (executing at
runtime) is a derived class from our code behind class. So all the control
reference we declare in the codebehind must be protected or public so that
the derived page class( dynamically compiled at runtime) can accessing
these control reference properties.
2. For WithEvent, it's just help to simplify our work for registering
event handler for controls, when we don't mark control reference with
WithEvent, we must use "AddHandler" to explicitly register event handler
for control's event.
When declaring with "WithEvent" on a certain Control( eg. ctrl1). Then,
when we define a event handler function like:
proteced SUB ctrl1_clicked(.....)
.....
end sub
we can use the " handles" keyword to bind the event handler, like:
Private Sub ctrl1_Click(.........) Handles ctrl1.Click
...........
BTW, since I'm more familiar with C# so generally I don't care much about
the VBNET's withevent syntax
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Terry Holland" <
[email protected]>
| References: <OcP#
[email protected]>
<
[email protected]>
<
[email protected]>
<#
[email protected]>
<
[email protected]>
<
[email protected]>
| Subject: Re: Getting Started with Web User Control
| Date: Thu, 28 Jul 2005 17:15:48 +0100
| Lines: 209
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: host240.multiserv.com 194.200.135.240
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:10151
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Thanks
|
| I had previously been using the line
|
| Private WithEvents MyControl1 as MyControl.
|
| My code failed to respond to event using this declaration
|
| I studied your code and changed my declaration to
|
| Protected WithEvents MyControl1 as MyControl.
|
| My code worked after setting to Protected.
|
|
| I notice that you also use
|
| Protected MyControl1 as MyControl. '(No WithEvents)
| and in the Form_Load you use the AddHandler ....
|
| What are the differences between to two diff methods? Both methods work
if
| the control is declared as Protected
|
| Thanks
|
| Terry Holland
|
|
|
|
| | > Hi Terry,
| >
| > I've attached the VB.NET one in this message. Please feel free to let me
| > know if you meet any problems getting it or if anything else we can
help.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure!
www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
| > | X-Tomcat-ID: 18388535
| > | References: <OcP#
[email protected]>
| > <
[email protected]>
| > <
[email protected]>
| > <#
[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain
| > | Content-Transfer-Encoding: 7bit
| > | From: (e-mail address removed) (Steven Cheng[MSFT])
| > | Organization: Microsoft
| > | Date: Thu, 28 Jul 2005 00:57:37 GMT
| > | Subject: Re: Getting Started with Web User Control
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | Message-ID: <
[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | Lines: 109
| > | Path: TK2MSFTNGXA01.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.webcontrols:10122
| > | NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
| > |
| > | No problem. Since C# is my prefered one so I always use C# at the
first
| > | brush
| > |
| > | I'll rewrite a VB.NET one and attache it later.
| > |
| > | Thanks,
| > |
| > | Steven Cheng
| > | Microsoft Online Support
| > |
| > | Get Secure!
www.microsoft.com/security
| > | (This posting is provided "AS IS", with no warranties, and confers no
| > | rights.)
| > |
| > |
| > | --------------------
| > | | From: "Terry Holland" <
[email protected]>
| > | | References: <OcP#
[email protected]>
| > | <
[email protected]>
| > | <
[email protected]>
| > | | Subject: Re: Getting Started with Web User Control
| > | | Date: Wed, 27 Jul 2005 12:05:07 +0100
| > | | Lines: 85
| > | | X-Priority: 3
| > | | X-MSMail-Priority: Normal
| > | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| > | | Message-ID: <#
[email protected]>
| > | | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | | NNTP-Posting-Host: host240.multiserv.com 194.200.135.240
| > | | Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| > | | Xref: TK2MSFTNGXA01.phx.gbl
| > | microsoft.public.dotnet.framework.aspnet.webcontrols:10110
| > | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | |
| > | | Steven
| > | | I have managed to download your attachment. would it be possible to
| > | provide
| > | | an example in vb?
| > | |
| > | | | > | | > Thanks for Brock's informative inputs.
| > | | >
| > | | > Hi Terry,
| > | | >
| > | | > As for the question you mentioned, generally the simplest means is
| to
| > | | > declare a public custom event property in the Usercontrol and
| > register
| > | the
| > | | > eventhandler in the host page's class so that we can hook the
| > | event.(Also
| > | | > we need to raise that event in our usercontrol's postback event
| > code).
| > | | > I've attached a simple demo in this message's attachment. You can
| also
| > | | have
| > | | > a look if you have interests.
| > | | >
| > | | > Hope helps. Thanks,
| > | | >
| > | | > Steven Cheng
| > | | > Microsoft Online Support
| > | | >
| > | | > Get Secure!
www.microsoft.com/security
| > | | > (This posting is provided "AS IS", with no warranties, and confers
| no
| > | | > rights.)
| > | | > --------------------
| > | | > | Message-ID: <
[email protected]>
| > | | > | From: Brock Allen <
[email protected]>
| > | | > | Subject: Re: Getting Started with Web User Control
| > | | > | References: <OcP#
[email protected]>
| > | | > | Mime-Version: 1.0
| > | | > | Content-Transfer-Encoding: 8bit
| > | | > | Content-Type: text/plain; charset=iso-8859-1; format=flowed
| > | | > | X-Newsreader: JetBrains Omea Reader 469.1
| > | | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | | > | Date: Tue, 26 Jul 2005 08:16:42 -0700
| > | | > | NNTP-Posting-Host: c-66-30-185-175.hsd1.ma.comcast.net
| 66.30.185.175
| > | | > | Lines: 1
| > | | > | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| > | | > | Xref: TK2MSFTNGXA01.phx.gbl
| > | | > microsoft.public.dotnet.framework.aspnet.webcontrols:10093
| > | | > | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.webcontrols
| > | | > |
| > | | > | You need have have your UserControl raise its own event. Here's
an
| > | | > example:
| > | | > |
| > | | > |
http://odetocode.com/Articles/94.aspx
| > | | > |
| > | | > | -Brock
| > | | > | DevelopMentor
| > | | > |
http://staff.develop.com/ballen
| > | | > |
| > | | > |
| > | | > |
| > | | > | > I am developing an vb.net web application and am noticing a
lot
| of
| > | | > | > pages need a very similar set of controls. Im attempting to
| > | | > | > encapsulate these into a web user control but am having real
| > | | > | > difficulties.
| > | | > | >
| > | | > | > Could someone send me some example code for this very simple
| > | scenario
| > | | > | >
| > | | > | > MyControl.ascx
| > | | > | > ===========
| > | | > | > one textbox and a submit button
| > | | > | > MyPage.aspx
| > | | > | > =========
| > | | > | > an instance of MyControl and a label
| > | | > | > From MyPage.aspx, I want to be able to detect the button_click
| of
| > | the
| > | | > | > button on the user control, and populate the label with the
| value
| > | that
| > | | > | > is in the user control's textbox.
| > | | > | >
| > | | > | > I know this is a very simple problem, but all of the examples
| > that I
| > | | > | > have looked at have not produced the result that I am after.
| > | | > | >
| > | | > | > thanks in advance
| > | | > | >
| > | | > | > Terry Holland
| > | | > | >
| > | | > |
| > | | >
| > | | > |
| > | | > |
| > | |
| > | |
| > | |
| > |
| > |
|
|
|