Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2004, 09:32 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default VS.net Question : Protected with Events

my visual studio.net 2003 is putting "protected with events for the server controls (see below)" in my code behind files; whenever I am working with my web form files. It is making my code more difficult to read. Please help.

***********
Protected WithEvents lblFirstName As System.Web.UI.WebControls.Label
    Protected WithEvents txtFirstName As...
************************
 
Old May 19th, 2004, 05:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

By default that's how it always does it. What problems are you having? If you need any other access (like between forms), you could use a property:

Public Property FirstName() As String
Get
  Return txtFirstName.Text
End Get
Set(Value As String)
  txtFirstName.Text = Value
End Set
End Property

If you are having problems within the web form, you shouldn't have any of these problems with protected access... Do you have any code to post maybe?

Brian
 
Old May 23rd, 2004, 08:06 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

When working with web forms, you need to have "Protected WithEvents" preceding the controls, well almost.

Protected: You have to have this. This is what establishes the link between the instance of the control that is declared in the HTML (<asp:button...>) and the instance in the code-behind (Protected WithEvents cmdClickMe As System.Web.UI.WebControls.Button).

WithEvents: This is not always required. This is used to provide the linkup of the event handlers so that you can create a method and use "Handles cmdClickMe.Click" to wire in the event. If you have a control on a web form that does not require events (which is more likely than not for things like labels or text boxes) you can remove the "WithEvents" keyword. Usually, the things that need event wiring are buttons, radio buttons, checkboxes, selects (dropdownlist or listbox), etc. If you want to use a text box's OnChanged event, then you would need it.

Readability is one thing, optimization is another. If you have a lot of controls on a page, it would probably be a little faster if you don't have "WithEvents" on controls that don't need it. On a page by page basis, you probably wouldn't notice it but once the application is being used my many users at the same time, things will be faster.

Peter
-------------------------
Work smarter, not harder





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fire events of a Active X dll in ASP.NET Brijendra Pandey ASP.NET 3.5 Professionals 1 October 4th, 2008 05:44 PM
Events in User Controls question Aaron Edwards ASP.NET 1.0 and 1.1 Basics 1 December 6th, 2005 02:59 PM
Events Question nhdw Beginning VB 6 2 February 23rd, 2004 04:00 PM
Define events in COM built in .NET roy VS.NET 2002/2003 1 October 22nd, 2003 11:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.