473,414 Members | 1,937 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,414 software developers and data experts.

How do I pass a web control reference to a class?

Sam
Hi,

I write my code behind in C# and everytime I need a new functionality, I
build a class for it and save it in a folder I call ClassLibrary.

My question is I don't know how to send my web controls to these classes.
For example, I created a standard States and Countries class which simply
gets a list of all US states and countries in the world from the database.

This took care of getting the necessary data from the database but I still
write a lot of repetitive code because I want to bind the data to the
specific DropDownList controls I use on my ASPX page. My classes are still
pretty useful as they go fetch the data for me but I realize that I'm not
using classes to their full potential.

Someone once told me that I could pass my DropDownList control to my class
and let the class, populate it, bind it to the control and whatever else I
need to do and return it to the ASPX page all ready to be used.

I'd appreciate some simple code samples or a pointer to a web page someone
already created so that I can see how this is done. Thanks for all your
help.

Thanks,

Sam
Nov 15 '05 #1
1 2654
Hi Sam,
This took care of getting the necessary data from the database but I still
write a lot of repetitive code because I want to bind the data to the
specific DropDownList controls I use on my ASPX page. My classes are still
pretty useful as they go fetch the data for me but I realize that I'm not
using classes to their full potential.
How do you keep the data inside that classes? if you keep it on a ArrayList
or collection then you can bind it to the ASP.net control and just call
DataBind() , Another solution would be create a strong typed collection of
State/Country and bind this collection to the control.
Someone once told me that I could pass my DropDownList control to my class
and let the class, populate it, bind it to the control and whatever else I
need to do and return it to the ASPX page all ready to be used.


And what would happen if you tomorrow decide to use these same classes for
a windows application?
You would have to write code to do the same thing. Another scenario would
be if you decide to bind the data to a control other than a DropDownList.
This imply that what you propose is not the best way, in fact the opposite
would be the correct use, create a collection of those objects in such a way
that you could use ANY control to bind them to.
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Nov 15 '05 #2

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

Similar topics

4
by: Todd | last post by:
Is it possible to pass an argument by reference through an event in C++ managed code? For example, can I do the following? public __gc class MyClass : public Control { public: __event...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
4
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
0
by: Sam | last post by:
Hi, I have a class that receives a DataGrid control and populates it. However, I need to do an OnItemCreated event because if I'm missing data in a certain column, I display a HyperLink control...
9
by: Frank Rizzo | last post by:
I've got a number of user controls on the web page. How can I pass some data to it? I don't see where the user control is instantiated in the page code-behind page. Thanks.
12
by: Phil Certain | last post by:
Hi, I'm trying to do something very simple...or at least it should be. I have created a host page (gen.aspx) and a very simple user control (us.ascx). The corresponding code-behind files are...
7
by: Rob | last post by:
lets assume I want to remove a control from a form that was dynamically created... If the button was added at design time, I can do the following... me.Controls.Remove(Button4) How may I...
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.