Thursday, March 29, 2012

OnSelectedIndexChange runs twice

Using 2.0...
My GridView is partially defined as such:ignore this message - sent it by accident - another one is coming...
thanks...
"VB Programmer" <dont@.emailme.com> wrote in message
news:%23aUWNKgTGHA.1160@.TK2MSFTNGP09.phx.gbl...
> Using 2.0...
> My GridView is partially defined as such:
>

OnSelectedIndexChange runs twice

Using 2.0...

My GridView is partially defined as such:ignore this message - sent it by accident - another one is coming...
thanks...

"VB Programmer" <dont@.emailme.com> wrote in message
news:%23aUWNKgTGHA.1160@.TK2MSFTNGP09.phx.gbl...
> Using 2.0...
> My GridView is partially defined as such:

OnSelectedIndexChanged does not fire with inherited Page class

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!
StuartAre you binding the dropdownlist in page_load without check for ispostback()
property.

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

<srallen@.gmail.com> wrote in message
news:1106060697.335855.60130@.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
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...
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
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.
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?
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?

OnSelectedIndexChanged Doesnt work *Resolved*

hi all;
I have place the following code in a OnSelectedIndexChanged sub..

Here is the code...

Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
LISTBOX2.ITEMS.CLEAR
dim selectstring as string
Dim cn1 As OleDbConnection = New OleDbConnection(ConfigurationSettings.appSettings("connectionstring"))
cn1.Open()
selectString = "select question_id, Question from questions where exam_id = " & listbox1.selecteditem.value
Dim cmd1 As OleDbCommand = New OleDbCommand(selectString, cn1)
Dim reader1 As OleDbDataReader = cmd1.ExecuteReader()
dim liadd as listitem

while(reader1.read())
liadd = new listitem
liadd.text = reader1("question").tostring
liadd.value = reader1("question_id").tostring
listbox2.items.add(liadd)
end while
End Sub


But it doesn't work. As you can see it must refresh the values of a list box, but simply nothing happens...

Is there a mistake somewher ??

ThanksWhat code do you have for the listbox in the HTML source?
Hi,

<asp:ListBox id="ListBox1" runat="server" Width="279px" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" Height="102px"></asp:ListBox>
You need to set the AutoPostBack property to true.

HTH

DJ
you r right, that was my mistake..

Thanks

OnSelectedIndexChanged does not fire with inherited Page class

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!
StuartAre you binding the dropdownlist in page_load without check for ispostback()
property.
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
<srallen@.gmail.com> wrote in message
news:1106060697.335855.60130@.c13g2000cwb.googlegroups.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
>
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...
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
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.
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?
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?
>

OnSelectedIndexChanged event does not work with the selection on the checkbox ( on the cel

Hi,

Does the OnSelectedIndexChanged event work when we mark on the checkbox on
the cell of Datagrid control ? I tried to call this event; it didn't
affect anything.
Do you know any event that make the selection on the checkbox work ? Please
give me your advise. ThanksCheck that the 'Handles' clause has not dissapeared...this is a known bug in
VS 2003...happens to me all the time-- really annoying!

"bienwell" wrote:

> Hi,
> Does the OnSelectedIndexChanged event work when we mark on the checkbox on
> the cell of Datagrid control ? I tried to call this event; it didn't
> affect anything.
> Do you know any event that make the selection on the checkbox work ? Please
> give me your advise. Thanks
>
Hi,

Here are my code. Please take a look on it. Thanks

Sub IndexChange_Command(sender As Object, e As EventArgs)
response.write("<BR>Account_ID ==> " &
DGrid_Carrier.SelectedItem.Cells(0).Text)
End Sub

<asp:DataGrid id="DGrid_Carrier" runat="server"
OnSelectedIndexChanged="IndexChange_Command"
OnItemDataBound="DGrid_ItemDataBound" OnItemCommand="DGrid_ItemCommand"
Width="353px" Font-Size="Smaller" Font-Names="Arial" CellSpacing="1"
CellPadding="3" AutoGenerateColumns="False"
================================================== ========
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:97A4CD58-B902-40D5-BFCD-7BE706B9F272@.microsoft.com...
> Check that the 'Handles' clause has not dissapeared...this is a known bug
in
> VS 2003...happens to me all the time-- really annoying!
> "bienwell" wrote:
> > Hi,
> > Does the OnSelectedIndexChanged event work when we mark on the checkbox
on
> > the cell of Datagrid control ? I tried to call this event; it didn't
> > affect anything.
> > Do you know any event that make the selection on the checkbox work ?
Please
> > give me your advise. Thanks

OnSelectedIndexChanged event does not work with the selection on t

Check that the 'Handles' clause has not dissapeared...this is a known bug in
VS 2003...happens to me all the time-- really annoying!
"bienwell" wrote:

> Hi,
> Does the OnSelectedIndexChanged event work when we mark on the checkbox on
> the cell of Datagrid control ? I tried to call this event; it didn't
> affect anything.
> Do you know any event that make the selection on the checkbox work ? Pleas
e
> give me your advise. Thanks
>
>Hi,
Here are my code. Please take a look on it. Thanks
Sub IndexChange_Command(sender As Object, e As EventArgs)
response.write("<BR>Account_ID ==> " &
DGrid_Carrier.SelectedItem.Cells(0).Text)
End Sub
<asp:DataGrid id="DGrid_Carrier" runat="server"
OnSelectedIndexChanged="IndexChange_Command"
OnItemDataBound="DGrid_ItemDataBound" OnItemCommand="DGrid_ItemCommand"
Width="353px" Font-Size="Smaller" Font-Names="Arial" CellSpacing="1"
CellPadding="3" AutoGenerateColumns="False">
========================================
==================
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:97A4CD58-B902-40D5-BFCD-7BE706B9F272@.microsoft.com...
> Check that the 'Handles' clause has not dissapeared...this is a known bug
in
> VS 2003...happens to me all the time-- really annoying!
> "bienwell" wrote:
>
on
Please