How to execute event code for DropDownList?

W

Waldy

Hi there,
when you double click a drop down control on a web form, it
creates the OnSelectedIndexChanged function placeholder in the code behind
file. How do you then get that code to execute? Changing the selection of
the drop down does not return to the server even though I have the
runat=server tags on the controls. A button on the same page does run the
OnClick event code in when you click it. I tried setting the AutoPostback
setting to true, and then the page gets re-loaded, but it still does not
execute the attached event code.

What am I missing?
 
P

Peter Bucher [MVP]

Hello Waldy
when you double click a drop down control on a web form, it
creates the OnSelectedIndexChanged function placeholder in the code behind
file. How do you then get that code to execute? Changing the selection
of the drop down does not return to the server even though I have the
runat=server tags on the controls. A button on the same page does run the
OnClick event code in when you click it. I tried setting the AutoPostback
setting to true, and then the page gets re-loaded, but it still does not
execute the attached event code.
The only thing you need is to set AutoPostBack of the Control to "true".
You said, that its not working after that..... so let us see your Code,
to explore the issue...
 
W

Waldy

Hi there,

Peter Bucher said:
so let us see your Code,

It's not easy as it is a large project. I created a new page to demonstrate
the problem and it works as expected on that page. What determines whether
or not event code is executed at the server? The output of the problem page
and the new page looks exactly the same as far as the dropdown is concerned.
The only javascript is calling the __doPostback method.
 
P

Peter Bucher [MVP]

Hi Waldy
It's not easy as it is a large project. I created a new page to
demonstrate the problem and it works as expected on that page. ok

What determines whether or not event code is executed at the server? The
output of the problem page and the new page looks exactly the same as far
as the dropdown is concerned. The only javascript is calling the
__doPostback method.
This can vary by different things.
In the included ASP.NET Components is that mainly a Javascript caused
postback with some Parameters that match the ones where on the Server
expected.

Its now difficult to say whats the problem in your issue.
Please show the two similar small Parts of the output...
.... maybe theres a difference to catch.
 
S

Stan

Hi there,



It's not easy as it is a large project.  I created a new page to demonstrate
the problem and it works as expected on that page.  What determines whether
or not event code is executed at the server?  The output of the problem page
and the new page looks exactly the same as far as the dropdown is concerned.
The only javascript is calling the __doPostback method.

Are you sure that the dropdown control is failing to postback?

If you are using Visual Studio and can run the project in debug mode,
one way to check this is to put a line or two of passive code in the
page_load event that executes when IsPostback is true. Then put a
debug break there. Run the page and click the dropdownlist. If it's
posting back then debug will halt it for you to see.

A much more common problem is the designated event code handler not
being executed on postback. This can happen after extensive editing
where event handling routines are liable to become orphaned. For
example if you place a control on the page, use the click method to
autogenerate an event "placeholder" then delete the control and put
back later leads to a situation where the original event code will not
be "wired up" to anything and the compiler just ignores it.

HTH
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top