Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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
  #1 (permalink)  
Old February 20th, 2006, 09:37 AM
Registered User
 
Join Date: Jun 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default addhandler catch 22

Hi,

I have an (in advance) unknown number of dropdownlists in an arraylist. I add a handler like this:

AddHandler arraylist(i).SelectedIndexChanged, AddressOf SomeDropDownList_SelectedIndexChanged

Now I want to make the following event handler:

Private Sub SomeDropDownList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
   DoSomething()
End Sub


Which does not work, because I have to define which dropdown it handles (!!??)

handles a_Specific_dropdown.SelectedIndexChanged.

But if I have to define which dropdown this event handles, what use is it to generate dropdowns at runtime (based on a database query)? Can't I define just one event handler, and let it handle all (new and unknown untill runtime) dropdownlists? This one is driving me crazy for a long time now... could somebody please help me?

Roog







  #2 (permalink)  
Old February 20th, 2006, 12:00 PM
Authorized User
 
Join Date: Feb 2006
Location: Ahmedabad, Gujarat, India.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to savan_thakkar Send a message via Yahoo to savan_thakkar
Default

Hi Friend,Really interesting question.
I spent a lot of time on it.I made the code in C#.net as below.
I wrote this code in Page_Load event.If you try to write it in any other event like Button_Click...then it won't work.If I m correct,you can register an event in only page_Initialize & page_Load event.

int no;
no=5;//Any other number from database
DropDownList d;
string s;
for(int i=0;i<no;i++)
{
    d=new DropDownList();
    d.Items.Add(new ListItem("AA","A"));
    d.Items.Add(new ListItem("BB","B"));
    d.ID="d" + i.ToString();
    d.AutoPostBack=true;
    d.SelectedIndexChanged+=new EventHandler(d_SelectedIndexChanged);
    p1.Controls.Add(d);
}
private void d_SelectedIndexChanged(object sender, EventArgs e)
{
    Response.Write("Gone");
}

Give me your feedback as soon as possible

Savan
  #3 (permalink)  
Old February 20th, 2006, 01:01 PM
Registered User
 
Join Date: Jun 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many thanks!!! It still does not work in page_load somehow... I just never tried to do it in Page_Init, assuming that it just didn't work. But in Page_Init it does work...

Thanks Savan!



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is addhandler for linkbutton.click not working rsearing ASP.NET 2.0 Basics 7 November 12th, 2007 06:06 PM
Listing 22-6 bpdsmark BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 2 March 26th, 2006 01:29 PM
Beware the AddHandler etoostr General .NET 0 November 6th, 2004 05:53 PM
AddHandler from String jbrenn@friends.edu Pro VB.NET 2002/2003 2 July 6th, 2003 04:18 PM





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