Custom Event Handler in Separate Class - Beginner Question

R

Ranginald

How could I go about creating a custom event handler for a web controls
method (e.g. OnSelectedIndexChanged) and have that method say,
ItemChanged() -- be called from a separate class (for example,
class1). My goal is to store some event handlers that I will use often
in a separate class so I don't have to retype them every time I need
them .


I. I am having a problem "telling" the web control (a dropdownlist
for example) to "look" in class1 for the ItemChanged() method.

II. No matter what I try (and I've been trying) I can't seem to get
the class to "see" the control on the page.

Sample Code:
=====
default.aspx
- a blank page -- all is being done with code (so I can learn)....

default.aspx.cs
using.....
page_load
{
DropDownList ddlOne = new DropDownList();
this.controls.add(ddlOne);
ddlOne.Item.Add("Sample One")
ddOne.Item.Add("Sample Two")
ddlOne.Item.Add("Sample Three")
ddlOne.SelectedIndexChanged = [[[somehow tell this method to find
the ItemChanged() method of Class1]]

}


class1.cs

pulbic void class1()
{
public void ItemChanged() //does this need to be in the
constructor to be called?
{
doSomething()
}
}

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top