[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

DropDownList OnSelectedIndexChanged event never firing

Posted on 2004-08-13
7
Medium Priority
?
9,323 Views
Last Modified: 2010-05-18
I have read through all the troubleshooting and other tickets posted on EE regarding this problem, however, it is still occuring with my code.
I have the following web form:

            <form name="myForm" id="myForm" method="post" RunAt="server">                                    
                  <asp:DropDownList ID="ddlType" OnSelectedIndexChanged="ddlType_SelectedIndexChanged" AutoPostBack="True" RunAt="server" />
            </form>



I have the following code:

            protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
            {
                  this.Redirect();
            }

            private void Redirect()
            {
                  //create url
                  string URL = "modifyAccomodation.aspx?";

                  if (null == searchTerm)
                        URL+= "?page=" + Convert.ToString(page-1);
                  else
                        URL+= "?page=" + Convert.ToString(page-1) + "&s=" + searchTerm;

                  //include ratings and types
                  if (type > 0)
                        URL += "&type=" + type;
                  if (rating > 0)
                        URL += "&rating=" + rating;
                  
                  //redirect
                  Response.Write(URL);
            }



The event NEVER fires!

Does the AutoPostBack attribute have to be set to True for event to fire?
Does it matter where you declare your databinding for the object?

I have also tried declaring event handler in the code as follows:

                  ddlType.SelectedIndexChanged +=new System.EventHandler(this.ddlType_SelectedIndexChanged);  


Really desperate to resolve this ASAP as I have to show client working page tomorrow.

Cheers.
0
Comment
Question by:smacca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 1

Assisted Solution

by:chmohan
chmohan earned 400 total points
ID: 11793276
did you try to declare another event and see if it fires? like ddl click or so? also place an alert or so to see if u actually come to the first event before redirect
0
 
LVL 9

Expert Comment

by:Rodney Helsens
ID: 11793278
Are you populating the DropDownList with a DataBind()?
If so, make sure you are checking is !Page.IsPostBack otherwise your going in circles.
0
 

Author Comment

by:smacca
ID: 11793296
If I place the databind in a condition with !Page.IsPostBack, none of the list options are displayed.
Why is it that you have to do this?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:smacca
ID: 11793312
chmohan: I am debugging and simply setting a break point within the event handler so the redirect never comes into play. The event is not firing at all and thus I can never break into the code in the handler.
0
 

Author Comment

by:smacca
ID: 11793384
I removed the following statements from the top of ASPX page and event is working now:

EnableViewState="false" AutoEventWireup="false"

Can anyone explain why this is happening?
0
 
LVL 9

Accepted Solution

by:
Rodney Helsens earned 600 total points
ID: 11793394
The IsPostBack property returns a value indicating whether the page is being loaded in response to a client postback, or if it is being loaded and accessed for the first time.

You should only need to databind your dropdownlist once when the page is initially loaded.. on postback, you want to process the form, not necessarily rebuild the form controls from the database again..

Why it does not populate when you put !Page.IsPostBack is a result of your page design, can you post some more of the relevant code?
0
 
LVL 9

Expert Comment

by:Rodney Helsens
ID: 11793539
When set to true asp.net will wire up the methods of the page class with events, I believe this is more for VB guys than c#.

If you set AutoEventWireUp = false, which I believe is the default for c#, you need to assign event handlers manually, like you showed above, but also do it for the page load event.

What are you using for your IDE? VS.NET generates code like this when set to AutoEventWireUp=false;


            override protected void OnInit(EventArgs e) {
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            private void InitializeComponent() {
                  this.Load += new System.EventHandler(this.Page_Load);
            }

You would also need to add the dropdownlist event handler at this point.


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question