473,664 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Yet Another DropDownList.Se lectedIndexChan ged Dufus

4 New Member
Yep, that's me. I'll bet I've read a hundred articles somewhere or another, but I just can't get the thing to work.

I'm working on a custom solution. One of the major UIs includes a calendar-style presentation. The navigation controls at the top of the calendar include four LinkButton controls (prevYear, prevMonth, nextMonth, nextYear) and two DropDownList controls (monthSelector, yearSelector). The DropDownList webcontrols are set with AutoPostBack=tr ue. I have attached handlers to their SelectedIndexCh anged events.

All of the LinkButtons work perfectly. The DropDownLists successfully AutoPostBack. But I can't get my SelectedIndexCh anged handler to execute to save my life. Nagging me back in the recesses of my brain is the suspicion that I have solved this one before, but I still just cannot seem to get this to work.

Here's the Control Tree from the Trace, so you can see that these DDLs are buried pretty deep. The object "myCal" of type "Preaching.Web. UI.PreachingCal endar" is my custom control written entirely in C# and packaged up in a DLL.
Expand|Select|Wrap|Line Numbers
  1. __Page    ASP.pcal_test_aspx
  2.     ctl05    System.Web.UI.LiteralControl
  3.     ctl00    System.Web.UI.HtmlControls.HtmlHead
  4.         ctl02    System.Web.UI.HtmlControls.HtmlMeta
  5.         ctl03    System.Web.UI.HtmlControls.HtmlMeta
  6.         ctl04    System.Web.UI.HtmlControls.HtmlMeta
  7.         pageTitle    System.Web.UI.HtmlControls.HtmlTitle
  8.     ctl06    System.Web.UI.LiteralControl
  9.     ctl01    System.Web.UI.HtmlControls.HtmlForm
  10.         ctl07    System.Web.UI.LiteralControl
  11.         datasource    Preaching.Web.UI.PreachingEventSqlPager
  12.         ctl08    System.Web.UI.LiteralControl
  13.         myCal    Preaching.Web.UI.PreachingCalendar
  14.             myCal$ctl00    System.Web.UI.WebControls.Table
  15.                 myCal$ctl56    System.Web.UI.WebControls.TableRow
  16.                     myCal$ctl57    System.Web.UI.WebControls.TableCell
  17.                         myCal$prevYear    System.Web.UI.WebControls.LinkButton
  18.                         myCal$ctl58    System.Web.UI.LiteralControl
  19.                         myCal$prevMonth    System.Web.UI.WebControls.LinkButton
  20.                     myCal$ctl59    System.Web.UI.WebControls.TableCell
  21.                         myCal$monthSelector    System.Web.UI.WebControls.DropDownList
  22.                         myCal$yearSelector    System.Web.UI.WebControls.DropDownList
  23.                     myCal$ctl60    System.Web.UI.WebControls.TableCell
  24.                         myCal$nextMonth    System.Web.UI.WebControls.LinkButton
  25.                         myCal$ctl61    System.Web.UI.LiteralControl
  26.                         myCal$nextYear    System.Web.UI.WebControls.LinkButton
  27.                         .....
  28.  
Here is the relevant C# code in the DLL.

Expand|Select|Wrap|Line Numbers
  1.             // Set up DropDownList navigators for the title
  2.             DropDownList monthSelector = new DropDownList();
  3.             monthSelector.ID = "monthSelector";
  4.             for (int i=0; i<12; i++) {
  5.                 monthSelector.Items.Add(new ListItem(DateTimeFormatInfo.InvariantInfo.MonthNames[i],
  6.                                                      (i+1).ToString()));
  7.             }
  8.             monthSelector.AutoPostBack = true;
  9.             monthSelector.EnableViewState = false;
  10.             monthSelector.SelectedIndex = VisibleDate.Month-1;
  11.             monthSelector.DataBind();
  12.  
  13.             DropDownList yearSelector = new DropDownList();
  14.             yearSelector.ID = "yearSelector";
  15.             for (int i=VisibleDate.Year-10; i<=VisibleDate.Year+10; i++) {
  16.                 yearSelector.Items.Add(new ListItem(i.ToString(), i.ToString()));
  17.             }
  18.             yearSelector.AutoPostBack = true;
  19.             yearSelector.EnableViewState = false;
  20.             yearSelector.SelectedIndex = 10;
  21.             yearSelector.DataBind();
  22.  
  23.             // Set up postback listeners for each control.
  24.             prevYear.Click += new EventHandler(OnPrevYearClick);
  25.             prevMonth.Click += new EventHandler(OnPrevMonthClick);
  26.             nextMonth.Click += new EventHandler(OnNextMonthClick);
  27.             nextYear.Click += new EventHandler(OnNextYearClick);
  28.             monthSelector.SelectedIndexChanged += new EventHandler(OnMonthSelectorChanged);
  29.             yearSelector.SelectedIndexChanged += new EventHandler(OnYearSelectorChanged);

Can anyone rescue me from my dufus-ness?
Jul 25 '07 #1
5 2181
Plater
7,872 Recognized Expert Expert
The DropDownLists successfully AutoPostBack. But I can't get my SelectedIndexCh anged handler to execute to save my life.
How do you know that they're posting back if their even never fires?
How do you know the event never fires?
Are you binding the datasource in the page_load (or analogue) function?
Jul 25 '07 #2
revbart
4 New Member
Plater, thanks so much for taking the time to help me. The spirit of fraternal volunteerism on these boards never ceases to amaze me. I'll try to answer your questions.

How do you know that they're posting back if their even never fires?
Answer: I know that AutoPostBack is working because whenever I change one of the DropDownLists, I witness a page reload.

How do you know the event never fires?
I know that the handler never executes because the very first line of the handler writes to the TraceContext indicating that it is beginning to execute. This message never appears in the trace. Also, of course, the desired calendar navigation never takes place.

Are you binding the datasource in the page_load (or analogue) function?
I'm calling DataBind in OnInit. The DDLs have the same value every time--they do not bind to any external datasource. As you can see in the original code, they simply present the months of the year and a list of years surrounding the present year.

The code creating the DDLs lies within a helper method (I think I named it something like CreateNavigatio nInterface) that is called by CreateChildCont rols().
Jul 25 '07 #3
revbart
4 New Member
Normally I would suspect that the controls hadn't been added to the Control tree when the event came looking for it, but since the LinkButton objects are directly adjacent to these DropDownList controls--even surround them--the fact that the LinkButton controls catch all their events just fine makes me relatively certain that these DDLs are also present while we're raising postback events.
Jul 25 '07 #4
revbart
4 New Member
AHA!

I fixed it myself. The problem was one too many DataBind()s In the Page_Load method on the actual page itself, I allow for the querystring to set the VisibleDate on the initial load. I had put the loading of the variable in an if-block, but not the DataBind() call for the PreachingCalend ar. Thus, DataBind() was executing every time at Page_Load, whether a PostBack or not. The EnsureChildCont rols at LoadPostData was painstakingly putting all the controls in place, only to have them obliterated at the beginning of Page_Load, just before RaiseChangedEve nts. LinkButtons, I have learned, do it differently (get their events at a different time.

So, am I an even bigger Dufus for puzzling so long over this when the answer was right there in front of me all along? I'll let you decide. Right now, I really don't care, because all that matters is this functional code in front of me.
Jul 25 '07 #5
Plater
7,872 Recognized Expert Expert
I'm claiming victory
Are you binding the datasource in the page_load (or analogue) function?
Jul 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
9087
by: Donal | last post by:
I have 3 related dropdowns. When the 1st is changed, the 2nd is updated, and when the 2nd is changed, the 3rd is updated. When i change the 1st dropdown (sites), the SelectedIndexChanged fires and the 2nd dropdown (spaces) is updated. However, 'spaces' no longer has a SelectedIndexChanged event. Where did it go to? If I change 'spaces' (2nd dropdown) before it gets updated by the 1st (sites), its SelectedIndexChanged is fired and the...
4
5476
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
2
3044
by: Shiju Poyilil | last post by:
Hi ! I have a requirement wherein i am binding a datalist which contains a label (Caption for the field) and some literal hidden fields and a dropdown list. When I am binding to the datalist.. only the labels (caption) and the invisible literal controls are binded.. Now based on the invisible literal control values I get the information from DB to bind it with each dropdown list (I am doing this in the item databound event) Also based on...
0
2271
by: Tand35006 | last post by:
Hi, I hope some one can help with this. I have a basic webform with 2 DropDownLists and a single DataGrid. What I am trying to do is populate the first DDList from a dataset on Form_Load. I then want to use this 1st DDList to populate the 2nd DDList via the SelectedIndexChange Event. So far so good. all works up to this point. The next thing I'm trying to do is to use the 2nd DDList value in a queery to populate the Datagrid also...
1
578
by: sergeyr3 | last post by:
Hey guys, I am new here, so i hope this works out: I have a datagrid which I populate with data from XML file. In EditItemTemplate I have a dropdownlist. How do I fire myDataGrid_UpdateCommand upon SelectedIndexChanged event in the dropdownlist? thank you. -Sergey <ASP:DataGrid id="myDataGrid" runat="server"
4
1941
by: David | last post by:
Hi all, I am doing this in a web page... I have a dropdownlist that autopostback. This sets me a filter criteria for items to display in a datalist. In the datalist, I have edit capabilities, which opens a text box. When I click Update for the datalist (edit), then for some reason, the
11
5805
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
5
2528
by: Victorious1 | last post by:
Why doesn't the the SelectedIndexchanged event for my dropdownlist ever get executed? Why do I get a page not found error when I select a new item? My dropdownlist is within a form. The items for the dropdownlist are added at form load by a procedure. Autopostback is set to true, and viewstate is enabled. I have placed a stop at the first line of code for the SelectedIndexChanged event and I have determined that the code is not...
2
3295
by: jnoody | last post by:
The problem I am having is with the SelectedIndexChanged event not always firing or the SelectedIndex property not being correct when the event does fire. The code is below, but here are some details first. The DropDownList is actually a custom control called DropDownListWithCommandEvent that inherits from DropDownList. The reason I have created this is to create a DropDownList that will bubble a Command event to the containing...
0
8437
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
8861
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8778
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...
0
7375
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...
1
6187
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
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...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1759
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.