This is a very common issue that has to do with not checking for PostBack on Page_Load, which causes your DropDownList to load again on PostBack before the web form is processed. To ensure that the DropDownList gets loaded 1x
only, you will need to check for PostBack.
VB.NET Private Sub Page_Load(ByVal sender
As Object, ByVal e
As EventArgs)
If Not IsPostBack Then
' Code here to bind data to DropDownList
End If
End Sub
C# private void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Code here to bind data to DropDownList
}
}
However, there is one exception to this. When working with dynamically created controls you need to recreate the control on PostBack. Otherwise, an exception will be thrown when you attempt to access the dynamic control in your code on PostBack.
are you fill the data into the dropdown list from db. if it is work fine that you can get the selected data through when it is postback(dropdownlist) or click event(). if these two not help you. let you try it useing firefox. ie some time throwing such that
exception.
Raja.k
K.Raja MCA,
Software Engg.,
Mail : inrajak@yahoo.co.in
It also helps to use the Render event to handle reading the database off of the form before using the PageLoad event to rebuild the control with data from the database. This allows for rebinding of data driven controls every postback and still being able to
access form data entered prior to the postback. Page Init comes in handy too. Especially on Forms that are generated dynamically and then populated dynamically, then allowed to be edited.
However, there is one exception to this. When working with dynamically created controls you need to recreate the control on PostBack. Otherwise, an exception will be thrown when you attempt to access the dynamic control in your code on PostBack.
While working with Dynamic controls you would have to recreate all the controls again at post back..... you can avoid this by writing the code of creating the dynamic controls in Page_Init( )
StrongTypes
All-Star
30801 Points
6013 Posts
ASPInsiders
Why am I not able to get the value or text of the SelectedItem in my DropDownList on PostBack?
Dec 20, 2005 05:13 PM|LINK
This is a very common issue that has to do with not checking for PostBack on Page_Load, which causes your DropDownList to load again on PostBack before the web form is processed. To ensure that the DropDownList gets loaded 1x only, you will need to check for PostBack.
VB.NET
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
' Code here to bind data to DropDownList
End If
End Sub
C#
private void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Code here to bind data to DropDownList
}
}
Blake05
Contributor
2561 Points
511 Posts
Re: Why am I not able to get the value or text of the SelectedItem in my DropDownList on PostBack...
Dec 21, 2005 05:21 PM|LINK
Blog - Website: windowscoding.com
StrongTypes
All-Star
30801 Points
6013 Posts
ASPInsiders
Re: Why am I not able to get the value or text of the SelectedItem in my DropDownList on PostBack...
Dec 21, 2005 05:32 PM|LINK
PeterBrunone
All-Star
18495 Points
3683 Posts
MVP
Re: Why am I not able to get the value or text of the SelectedItem in my DropDownList on PostBack...
Dec 22, 2005 07:00 AM|LINK
Another exception is EasyListBox. No viewstate worries, no problem; you can re-bind and your selections stay intact.
MS MVP, ASP.NET
Founder, EasyListBox.com
Do the impossible, and go home early.
Blake05
Contributor
2561 Points
511 Posts
Re: Why am I not able to get the value or text of the SelectedItem in my DropDownList on PostBack...
Dec 24, 2005 02:22 PM|LINK
Blog - Website: windowscoding.com
Amrits4eva
Member
17 Points
4 Posts
Re: Why am I not able to get the value or text of the SelectedItem in my DropDownList on PostBack...
Oct 23, 2006 12:50 PM|LINK
Hi all,
There is no need for the post backs, to check for the selected value in the drop down
Easier and faster way is to use javascript code to check for the option selected in the dropdown list.
Cheers..
Amrit.
inrajak
Member
90 Points
26 Posts
Re: Why am I not able to get the value or text of the SelectedItem in my DropDownList on PostBack...
Nov 30, 2006 10:17 AM|LINK
Hi friends
are you fill the data into the dropdown list from db. if it is work fine that you can get the selected data through when it is postback(dropdownlist) or click event(). if these two not help you. let you try it useing firefox. ie some time throwing such that exception.
Raja.k
Software Engg.,
Mail : inrajak@yahoo.co.in
cgraving
Member
111 Points
42 Posts
Re: Why am I not able to get the value or text of the SelectedItem in my DropDownList on PostBack...
Jan 15, 2007 11:17 PM|LINK
Dhaliwal
Participant
992 Points
231 Posts
Re: Why am I not able to get the value or text of the SelectedItem in my DropDownList on PostBack...
Jan 22, 2007 10:07 AM|LINK
While working with Dynamic controls you would have to recreate all the controls again at post back..... you can avoid this by writing the code of creating the dynamic controls in Page_Init( )
srinivas815
Member
2 Points
1 Post
Re: Why am I not able to get the value or text of the SelectedItem in my DropDownList on PostBack...
Jan 22, 2007 03:52 PM|LINK
Hi
I expect that the control is fetching the data two times
1. At the time of load
2. At the time of rendering
Please try to place the entire code in the pre render event and give a try.
Thanks,
Srinivas.