473,669 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best Practice Question

I have a question on whether or not this is good practice. I have a
fairly complex web user control (a datalist embedded in a datalist
with lots of controls) that I will call Usercontrol1 and a lot of code
in the codebehind of the user control for setting/getting properties
of the controls. What I would like to do is create a class like this:

public class MyClass
{
UserControl1 _userControl

public MyClass(UserCon trol1 userControl)
{
_userControl = userControl;
}

public void SetView()
{
_userControl.Te xtBox1.Text = "sometext";
Label labale1 =
(Label)_userCon trol.GetControl ("controltofind ");
etc., etc.
}
}
I want to instantiate MyClass in the UserControl1 codebehind using the
this keyword and use MyClass to set the values for my user control.

MyClass myClass = new MyClass(this);

Is this good practice and will this create any issues? I know in
theory it will work, because I have tested it (at least with one web
user, but not with multiple web users).

This would make the codebehind much more compact and readable.
Nov 22 '05 #1
4 1361
I'm not sure if this is a good typical practice, but I can tell what I would
do. I would create a base class that inherits from UserControl. All the user
controls you create must inherit from the base user control. That way, you
get to reuse your code and you will be able to deal with multiple controls
polymorphically .

=============== =============
Hayato Iriumi (hi*****@hotmai l.com)
Blog: http://www.vbaspcoder.com

"Chris" <cc****@unfi.co m> wrote in message
news:49******** *************** **@posting.goog le.com...
I have a question on whether or not this is good practice. I have a
fairly complex web user control (a datalist embedded in a datalist
with lots of controls) that I will call Usercontrol1 and a lot of code
in the codebehind of the user control for setting/getting properties
of the controls. What I would like to do is create a class like this:

public class MyClass
{
UserControl1 _userControl

public MyClass(UserCon trol1 userControl)
{
_userControl = userControl;
}

public void SetView()
{
_userControl.Te xtBox1.Text = "sometext";
Label labale1 =
(Label)_userCon trol.GetControl ("controltofind ");
etc., etc.
}
}
I want to instantiate MyClass in the UserControl1 codebehind using the
this keyword and use MyClass to set the values for my user control.

MyClass myClass = new MyClass(this);

Is this good practice and will this create any issues? I know in
theory it will work, because I have tested it (at least with one web
user, but not with multiple web users).

This would make the codebehind much more compact and readable.

Nov 22 '05 #2
Thanks! This solution presents its own problems, but I think it will
work. The problem is that I have a datalist (with about 20
textboxes/dropdownlists) embedded in another datalist (with about 20
textboxes/dropdownlists). Thus, I really have to make the base class
abtsract, since I really do not want an aspx webpage associated with
it, I do not want this class to be instantiated. I will then create
the methods in the abstract class to do the formatting and then call
these in the derived class (which will have the assoicated aspx page
associated with the embeddded datalists). I had initially wanted to
create one user control for the parent list and then another for the
embedded child list, but I was not familiar with doing this and it got
to be fairly complex anyway. With your idea, by using inheritance, I
can create much cleaner code. It will not be very extensible, but
this is for a very specific project anyway so I really only need one
derived class.
Nov 22 '05 #3
Hello,
You mentioned that the solution I suggested may not be extensible. How
not extensible is it? Would you share with me?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 22 '05 #4
What I did is I created an abstract base class derived from
System.Web.UI.U serControl. I placed most of the methods for
formatting and getting the values from the controls here. Since my
control is a datalist (child)embedded in another datalist (parent), I
have to use findcontrol() a lot to access the embedded controls to get
their values. I also have to dynamically wire the events for the
child datalist and some of the other embedded controls (which there
are 40+ for the two datalists combined). Thus, there is a lot of
code. One problem I had is that I tried to create a web user control
as the base class, with the HTML and derive a class from this to see
if it would work. Unfortunately, DOTNET does not have this capability
(from what I understand, if this is possible, please let me know). So
I ended up having to create a web user control derived from my
abstract base class with the HTML elements in the derived web user
control. This works, but what I don't like about it is that the HTML
in the derived control is tied so tightly to the abstract class'
methods and vice-versa. Why I said it was not that extensible is just
the fact that unless a user had access to the HTML in my derived
control, the abstract base class would not make much sense, because
the code is so closely tied. I probably could have designed this whole
thing better, but when I began, I did not know how to do the datalist
embedded in another datalist, so I just wanted to make it work at
first.
Anyway, the end result of all this is that I now have much better
organized code (the derived class just has the events methods and a
couple of others) and a really nice user control for my project. I
just wish that I could have placed the HTML in the base class rather
than the derived class, to make the base class one self-contained
unit. That is why I said it was not that extensible, because the HTML
has to be recreated on any other derived user controls. However, that
was not my purpose here, since this control has a very specialized
role for my one project and I really just wanted cleaner code.
Nov 22 '05 #5

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

Similar topics

5
2805
by: martin | last post by:
Hi, Is there any best practice guidelines or examples for threadsafe logging? I have to write an auditlogging class for a website. The auditlog will be stored in files on the local filesystem. A new file file is created by the interval of 24 hours. /m
136
9312
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
17
8030
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to read or modify this string so I don't want to store it in an INI / Text file or in registery. Can someone please tell me the best practice for this. Thanks Mike
4
1753
by: Guy Noir | last post by:
Hello. Is there a pattern or best practice for the following scenario? I have a list of items I would like to compare. The number of items are decided at runtime. ObjectA, ObjectB, ObjectC......ObjectX I want to process a comparison for each of these projects. So, for
6
1463
by: AlexT | last post by:
Folks Please bear with me - I'm not a real ASP pro... I need some advice about the following problem: I have "inherited" of a working ASP site which is hosted on a collocated IIS machine. At some point the site offers the possibility for any user to fill a
10
2982
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? public class MyClass private _variableName as integer public property VariableName as integer
3
1809
by: cbrown | last post by:
I am rebuilding an existing application that relies on an SQL DB. The app is a scheduling/employee management program. My question pertains to best practices in dotnet and database. I use a 3 tier model and have custom classes for things like Employees. What comes to question is when I load an Employee from my DB, I populate the properties of the object with the data in the dataset. When I want to view the employee on a form, i bind...
16
2794
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
3
1983
by: Alan Isaac | last post by:
This is a simple question about actual practice. I just want to know how you (yes you) are approaching this problem. The problem: What is the recommended packaging of demo scripts or test scripts for a package to be distributed to others to "play with". (I.e., without "installing".)
5
2882
by: Frank Millman | last post by:
Hi all This is not strictly a Python question, but as I am writing in Python, and as I know there are some XML gurus on this list, I hope it is appropriate here. XML-schemas are used to define the structure of an xml document, and to validate that a particular document conforms to the schema. They can also be used to transform the document, by filling in missing attributes with default values.
0
8466
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8810
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8590
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2035
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.