By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,853 Members | 2,186 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,853 IT Pros & Developers. It's quick & easy.

OnSelectedIndexChanged does not fire with inherited Page class

P: n/a
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

Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Are you binding the dropdownlist in page_load without check for ispostback()
property.

--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

<sr*****@gmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
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

Nov 19 '05 #2

P: n/a
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...

Nov 19 '05 #3

P: n/a
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.

--
Matt Berther
http://www.mattberther.com
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

Nov 19 '05 #4

P: n/a
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.

Nov 19 '05 #5

P: n/a
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?

Nov 19 '05 #6

P: n/a
Hello Stu,

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

--
Matt Berther
http://www.mattberther.com
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?

Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.