473,769 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selected Index event not firing

I have a dropdown combo box on a form and I have its AutoPostBack property
set to true. When I select something from the list it does a postback and
then the Page_Load event fires followed by it's SelectedIndexCh anged event.

However, when I go back to this control again and select the first item in
the list, it does a postback and the Page_Load event fires, but the
SelectedIndexCh anged doesn't fire. Why does the SelectedIndexCh anged get
skipped when selecting the first item in the list?

In summary, I have a dropdown list. I select the 3rd item in the list and
the SelectedIndexCh anged fires like it should. As I step through the code I
see the selected index = 2. Now when I go back and select the first item in
the list and step through the code I can see the selected index =0 (changed
from 2), but the SelectedIndexCh anged doesn't fire.

How can I resolve this?

Thanks.

--
mo*******@nospa m.com
Nov 18 '05 #1
12 3992
Make sure the event is defined (instantiated) in the IntializeCompon ent
procedure.
--
Peter O'Reilly
Nov 18 '05 #2
Can you give me an example of how I would do that? (vb.net if you can....)
Its not in the IntializeCompon ent and its simply declared like this:

Protected WithEvents cmbShipMethod As System.Web.UI.W ebControls.Drop DownList
Thanks.

--
mo*******@nospa m.com
"Peter O'Reilly" <Pe***********@ timeinc.com!N!O !.S!P!AM!> wrote in message
news:ee******** *****@TK2MSFTNG P09.phx.gbl...
Make sure the event is defined (instantiated) in the IntializeCompon ent
procedure.
--
Peter O'Reilly

Nov 18 '05 #3
Hello,

Based on your description, I build a simple test web form. However, I
haven't found the problem you mentioned. I just add some code in
DropDownList1_S electedIndexCha nged:

Private Sub DropDownList1_S electedIndexCha nged(ByVal sender As Object,
ByVal e As System.EventArg s) Handles DropDownList1.S electedIndexCha nged
Response.Write( "changed")
End Sub

And add a breakpoint at the line. After run the application, the breakpoint
get stopped whenever I select a item in the dropdown list control.

Can you post some of your code to clarify the problem? Maybe we can get
more detail informaiton from that.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #4
It is really a strange problem! After check your code, I found it seems to
be related to your base page. If I added the control on a normal web form,
it worked. Especially, with the MoveControl method in base page. Everytime
we select a item, the code in MoveControls will be executed, and it cause
the problem. If I remove the MoveControls, and add the control in another
way:

Public Class zTestDropdown
Inherits BrowserTest.Bas ePage

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim cc As Control = Page.LoadContro l("shoppingcart .ascx")
cc.Visible = True
Me.ContentArea. Controls.Add(cc )
End Sub

This seems to fix the problem.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5
Hello,

This time the 'bad" line is:

Me.cellContentC ontainer.Contro ls.Clear()

If I replace it with

Me.cellContentC ontainer.Contro ls.RemoveAt(0)

Dim l1 As New LiteralControl
Me.cellContentC ontainer.Contro ls.Add(l1)

Me.cellContentC ontainer.Contro ls.Add(cc)

Then it seem to work.

Regarding all of these issues, I suggest you may consider frameset instead
embed asp.net user control. For example, in the default.aspx:

<td id="cellContent Container" vAlign="top" bgColor="#ccccf f" runat="server">

<iframe src=home.aspx></iframe>

</td>

How about this?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #6
I found one piece of information that may or may not lead to some insight:
I re-created this page as a stand alone page (did not inherit from the
basepage), and put all the html and code behind from the shoppingcart.as cx
into shoppingcart.as px and noticed I was still getting the same bad
behavior. After testing it I found that cmbShipMethod's viewstate was
false. After setting it to true, I found that everything worked OK. I'm
sure that ealier I had tested viewstate as both true and false on everything
I could find to see it that would help, but for some reason it helped on
this new page. So I went back to the derived page with shoppingcart.as cx
(the one I gave you in the above posting) and found that setting the
viewstate to true or false had no effect on the behavior. My conclusion
thus far is that there might be some problem with the dropdownlist's
viewstate from the user control or because the page is inheriting from the
base page, or a combo of both.

--
mo*******@nospa m.com
"moondaddy" <mo*******@nosp am.com> wrote in message
news:eL******** ******@TK2MSFTN GP11.phx.gbl...
This is getting really confusing and frustrating. The code that didn't work is code that was given to me in this user group. It worked under a previous scenario, but not this one. How should one know when to use what syntax?
This isn't documented. I'm not coming down on you as you are being a great help and I'm happy for that. However, as soon as the environment changes a bit, the code doesn't work again and I have to ask you again for a solution. Either I really don't know how to use the dropdown or it has some
shortcomings in these more complicated environments in which case the
development team needs to know about this if they don't already. OK enough of that rant.

Switching user controls is leading to lots of various problems so I'm going with a slightly different model. This one is where each user control
(controls used for the main content of a page) get their own page and each
page inherits from the basepage. This way there's no confusion as to which page a control is in. For example, the products.ascx lives in
products.aspx, aboutus.ascx lives in aboutus.aspx, and so on. Not as
elegant (or fast... I think) as one page-many controls, but more stable.

So back to this troubled dropdown. Your code below worked when trading out a control for another, but this time the shoppingcart control is constant in the shoppingcart page and we're back to the same old problem.

I'm attaching a new sample project. run this project using default.aspx as the startup page and click
on the link on the left "Shoppingca rt Test" to load the shopping cart for
testing. You will see what I mean. If you can help with this it would be
great as this is the model I think I'm going to go with.

As for your comment about using frames. I wish I could. I spent the first part of this project building it out in frames and it worked totally great. but for reasons I have to do away with frames and so here I am.

Thanks again!!!

--
mo*******@nospa m.com
"[MSFT]" <lu******@onlin e.microsoft.com > wrote in message
news:Uu******** *****@cpmsftngx a10.phx.gbl...
Hello,

This time the 'bad" line is:

Me.cellContentC ontainer.Contro ls.Clear()

If I replace it with

Me.cellContentC ontainer.Contro ls.RemoveAt(0)

Dim l1 As New LiteralControl
Me.cellContentC ontainer.Contro ls.Add(l1)

Me.cellContentC ontainer.Contro ls.Add(cc)

Then it seem to work.

Regarding all of these issues, I suggest you may consider frameset instead embed asp.net user control. For example, in the default.aspx:

<td id="cellContent Container" vAlign="top" bgColor="#ccccf f"

runat="server">

<iframe src=home.aspx></iframe>

</td>

How about this?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



Nov 18 '05 #7
To get the event from controls. Viewstate is necessary. Regarding the
issue, I can't open you sample project "BsPgSample ", it reported an error
when I open ShoppingCart.as px. I check the code with Notepad and find the
movecontrols method is still used. This may the root cause of the problem

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #8
I have to use the movecontrols method because the base page has table in it
which is used to hold a user control for the header and another user control
for the left nav bar. with our the movecontrols method, things dont get
placed on the page correctly. the header and nav bar are on the bottom of
the page.

What kind of error did you get? could you open any other page? I would
like to send you a working sample if possible. This whole thread stems from
a shortage of good documentation and sample code for base pages in vb.net
and I've spend a ton of time trying to get a solid model working. It would
be nice if someone from MS could help in getting a proper base page working.
Please let me know what I can do so send you a sample that runs.

Thanks.

--
mo*******@nospa m.com
"[MSFT]" <lu******@onlin e.microsoft.com > wrote in message
news:5D******** ******@cpmsftng xa10.phx.gbl...
To get the event from controls. Viewstate is necessary. Regarding the
issue, I can't open you sample project "BsPgSample ", it reported an error
when I open ShoppingCart.as px. I check the code with Notepad and find the
movecontrols method is still used. This may the root cause of the problem

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #9
Thanks, I think this will fix the load problem: Attached are 2 text files,
one with the base page html and the other with the code behind. Delete the
existing base page out of the project I sent you (BsPgSample) and add a new
webworm and call it "Base.aspx" . Then add the html and code behind from the
attached text files and it should run OK. Make sure that shopping.aspx
inherits from the new base correctly (Inherits BsPgSample.Base ).

Please let me know if this fixed the load problem and what you can find out.

--
mo*******@nospa m.com
"[MSFT]" <lu******@onlin e.microsoft.com > wrote in message
news:vo******** ******@cpmsftng xa10.phx.gbl...
I can open the solution. But when I double click to open shoppingcart.as px, there was an error. I have attached it in this message.

Luke

Nov 18 '05 #10

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

Similar topics

9
56529
by: Steffen Laser | last post by:
Hi group, I have a problem that I already have posted to the german C# newsgroup. Since nobody could help me there, I'd like to try it here again: I set the selected item of a combobox like this: myCombo.SelectedItem = 3; But after that the ComboBox displays only the first entry of the list. When I add the line
2
1800
by: Eric Jelinek | last post by:
I need a little help here, I have a list view that may contain only a few items. If the size of the listview is larger then what I need to hold the items, and then the user click on whitespace, how can maintain that an item must be selected? Currently in the MouseDown Event I .GetItem(e.X, e.Y) and check to see if it is null, if it is then I set the last item in the list to item.selected=true. Unfortunately, the SelectedIndexChange event is...
5
3370
by: tshad | last post by:
Is there a way to allow a user to press a radio button if it is already selected? There is an onCheckedChanged event that fires when the person presses the button and it is isn't selected already. If it is selected, it doesn't fire. This isn't the case with a checkbox. The event fires whether the control is already checked or not. Thanks,
5
13851
by: Steve Jones | last post by:
Hi there, I am working with web forms, and am finding that the standard list of combo box events is dramatically reduced when using the dropdownlist. For example, the only event that I can see that will trigger when a user selects a different menu item is 'selected index changed'. I can confirm with a separate button that the index has in fact changed after a pulldown selection takes place, yet the internal 'selected index changed'...
5
13394
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able to get a Boolean value TRUE or FALSE when a checkBox is selected. When the checkBoxList was out of the DataList i used "OnSelectedIndexChanged" and it was returning what i wanted but if its in a
1
2411
by: Andy | last post by:
Hello, I have a datagrid within another datagrid. The innder datagrid contains a dropdownlist which fires an event as index change (OnSelectedIndexChanged). I can get the ItemIndex of the dropdownlist using this code below: ((DataGridItem)((DropDownList)Sender).NamingContainer).ItemIndex; This returns the ItemIndex of the dropdownlist of the inner datagrid.
3
10377
by: n. Smith | last post by:
Hi All, Is it normal that the ListView fires the selectedinexchange event twice? I have a LvLoaners list view item that updates 3 text boxes (code below), when I click on an item. I have set MultiSelect to False. The first click goes as planned, but all subsqequent clicks seem to fire the event twice. The first firing triggers an ArgumentException, resulting in nItem not being initialised. That's why I have the first
5
4838
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
11
5815
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
0
9423
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,...
1
9997
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
9865
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
8873
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
6675
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
5310
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.