My DropDownList handler isn't executing.

D

darrel

I have a asp:dropdownlist set to autopostback.

However, my handler doesn't seem to execute (even though there is a
postback).

Here's the DDL:

<asp:dropdownlist id=ddl_districtSelect runat="server" AutoPostBack="True">
(list items)
</asp:dropdownlist>

and the handler:

Private Sub ddl_districtSelect_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddl_districtSelect.SelectedIndexChanged
response.Write("MONKEY")
End Sub

Any reason why this wouldn't be executing?

-Darrel
 
D

darrel

However, my handler doesn't seem to execute (even though there is a
postback).

Hmm...I also have another problem. The auto-postback isn't retaining the
selected value. It keeps reverting to the first item.

I don't normally use drop down auto-postbacks, so am I just completely not
'getting' some fundamental concept here?

-Darrel
 
M

Marina

Are you rebinding the data every time the page loads? This may be your
problem. You only need to bind once.
 
D

darrel

Are you rebinding the data every time the page loads? This may be your
problem. You only need to bind once.

Nope. no databinding at all. Just a simple option list right in the HTML
itself.

-Darrel
 
J

John Horst

If your ddl is reverting to the first item and not keeping the selected
item from prior to the postback, you are probably calling databind() on
the control on the postback. Here is a general rule of thumb for
getting data, binding to it and the Page_Load event:

In page load, before checking the IsPostBack property, get your data.
Then check if the page is being posted back. If not, call DataBind on
the controls.

Page_Load(<<args>>)
{
// get data.
dataAdapter.Fill(dataTable);

// check for postback.
if (!this.IsPostBack)
{
control.DataBind();
}
}

The exception to this would be if you are using a datareader for your
ddl. Then get the datareader and bind the control only if the page is
NOT a postback.

Page_Load(<<args>>)
{

// check for postback.
if (!this.IsPostBack)
{
// get data reader.
SqlDataReader dr = someCommand.ExecuteReader();
control.DataSource = dr;
control.DataTextField = "SomeTextField";
control.DataValueField = "SomeValueField";
control.DataBind();
}
}

John


-----Original Message-----
From: darrel [mailto:[email protected]]
Posted At: Friday, August 26, 2005 1:02 PM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: My DropDownList handler isn't executing.
Subject: Re: My DropDownList handler isn't executing.

However, my handler doesn't seem to execute (even though there is a
postback).

Hmm...I also have another problem. The auto-postback isn't retaining the
selected value. It keeps reverting to the first item.

I don't normally use drop down auto-postbacks, so am I just completely
not 'getting' some fundamental concept here?

-Darrel
 
D

darrel

Do they all have unique values?

Yes. Here's the full markup:

<asp:dropdownlist id=ddl_districtSelect runat="server" AutoPostBack="True">
<asp:ListItem Value="first">1st District</asp:ListItem>
<asp:ListItem Value="second">2nd District</asp:ListItem>
<asp:ListItem Value="third">3rd District</asp:ListItem>
<asp:ListItem Value="fourth">4th District</asp:ListItem>
<asp:ListItem Value="fifth">5th District</asp:ListItem>
<asp:ListItem Value="sixth">6th District</asp:ListItem>
<asp:ListItem Value="seventh">7th District</asp:ListItem>
<asp:ListItem Value="eigth">8th District</asp:ListItem>
<asp:ListItem Value="ninth">9th District</asp:ListItem>
<asp:ListItem Value="tenth">10th District</asp:ListItem>
</asp:dropdownlist>

-Darrel
 
D

darrel

If your ddl is reverting to the first item and not keeping the selected
item from prior to the postback, you are probably calling databind() on
the control on the postback.

I'm not in this case. Just a static list of asp:listItems

Nowhere in my codebehind am I databinding to this list nor am I even
changing the selected item.

-Darrel
 
M

Marina

Have you recompiled your project since adding the handler?

If this is all that is going on, then the handler should be getting hit.
 
D

darrel

Have you recompiled your project since adding the handler?
If this is all that is going on, then the handler should be getting hit.

Aaarrrrrrrrrrrrrrggggggggggghhhhhhhhhhhhhhh!

I'm a dope. Turns out there was a stray FORM tag in the HTML (this was a
legacy ASP page that I'm slowly converting).

'doh!

-Darrel
 
J

John Horst

What is the EnableViewState property on the ddl set to? It should be
True.

John

-----Original Message-----
From: darrel [mailto:[email protected]]
Posted At: Friday, August 26, 2005 1:27 PM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: My DropDownList handler isn't executing.
Subject: Re: My DropDownList handler isn't executing.

If your ddl is reverting to the first item and not keeping the
selected item from prior to the postback, you are probably calling
databind() on the control on the postback.

I'm not in this case. Just a static list of asp:listItems

Nowhere in my codebehind am I databinding to this list nor am I even
changing the selected item.

-Darrel
 
D

darrel

What is the EnableViewState property on the ddl set to? It should be
True.

John

Hey John. See my other response. THis was a user-error problem. I was
migrating an old ASP page over and had missed a stray FORM tag that was
breaking everything below it.

A typical Friday mind fart on my part. ;o)

-Darrel
 
P

Pat

Darrel good you got it working

darrel said:
Aaarrrrrrrrrrrrrrggggggggggghhhhhhhhhhhhhhh!

I'm a dope. Turns out there was a stray FORM tag in the HTML (this was a
legacy ASP page that I'm slowly converting).

'doh!

-Darrel
 

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
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top