OnSelectedIndexChanged does not fire with inherited Page class

S

srallen

I have a simple page that has a dropdown with autopostback=true and
onselectedindexchanged is set to a function that never gets called
(checked during debug). This page is subclassed from custom class of
mine that I subclassed from Page.

I have overridden a couple of methods (OnPreRender, OnUnload, OnInit)
to provide for html template layout, all of the base functions are
called as well.

Can anyone lend some help as to why the SelectedIndexChanged event does
not fire when you use a custom Page class? I have to be doing something
in the custom code to prevent the event from firing, I just don't know
where.

Thanks a ton!
Stuart
 
S

Saravana

Are you binding the dropdownlist in page_load without check for ispostback()
property.
 
S

Stu

no, I do a check for IsPostBack with the Bind call...

I've narrowed the problem down some.

By overriding OnPreRender or OnLoad, somehow this causes the event not
to fire.

I moved all my templating code to OnInit and now I can get the event to
fire, its just that my template code is dependent on Session varaibles,
which are changed by the dropdown, so the session object isn't changed
when OnInit is run, only after OnLoad....

frustrated...
 
M

Matt Berther

Hello Stu,

I've had this happen for me if the Value property is not unique... Make sure
that if you're using ValueMember that each item in your datasource has that
property unique.
 
S

Stu

Thanks for the suggestion.. that wasn't it... If the set the page that
has the dropdown to use the regular Page class, the event will fire.
 
S

Stu

I re-worded the problem, perhaps this will help:


Ok here is the situation:

I have inherited System.Web.UI.Page into a custom class for page
templating.

For my template html, I create several LiteralControls and add them to
the controls collection. works fine.

Initially I placed this code in the OnInit method. Works good.
Part of my template code now displays a Session variable, this is part
of the problem.

A page that inherits the custom class has a DropDownList with
autopostback=true and OnSelectedIndexChanged event set to fire.
In the event, I change the value of that Session variable.
But since the template code is calling in OnInit, the page shows the
old session variable, you have to refresh the page to get the page to
show the latest session variable, this is bad.

So, I tried moving my template html controls to another overridable
method, moved it all to OnPreRender.
So, now, my OnSelectedIndexChanged event doesn't fire, b/c the
DropDownList does something screwy with the PreRender method.

So here in summary:
Need custom class to inherit Page class for templating.
Templated HTML material needs access to Session variables. (in what
override should this code live in?)
DropDownList needs to fire SelectedIndexChanged event to change Session
variable.
(how does the prior affect this, where can I put the prior so it
doesn't screw up the event from firing?)

Any ideas?
 
M

Matt Berther

Hello Stu,

Any possibility you could post the code that you have now that doesnt work?
We may be able to see something there...
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top