Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 19th, 2004, 09:32 AM
Friend of Wrox
Join Date: Jan 2004
Location: , , USA.
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...
Reply With Quote
  #2 (permalink)  
Old May 19th, 2004, 05:06 PM
Friend of Wrox
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts


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
  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?

Reply With Quote
  #3 (permalink)  
Old May 23rd, 2004, 08:06 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

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.

Work smarter, not harder
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 04:58 PM.

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