dropdownlist autopostback [Resolved]

Posted by Oswaldlily under ASP.NET on 12/27/2011 | Points: 10 | Views : 1193 | Status : [Member] | Replies : 3
In dropdownlist i has 3 values and separate button

when i select dropdownlsit value and click button it coming back to first position.

my expected result:
when i click first value and button ,corresponding value of first value shd display
when i click second value and button ,corresponding value of second value shd display
when i click third value and button ,corresponding value of third value shd display




Responses

Posted by: Saisindura on: 12/27/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
hi
just do autopostback=true

Thanks&Regards
srisai

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Suvendu on: 12/27/2011 [Member] Starter | Points: 25

Up
0
Down
You have to put few lines of code in the page load..

here is the code-

if(!Page.IsPostback)
{
//logic or, method for dropdown bind here

}

Explaination:

A page load event is called on two cases --1st when the page rendered to the browser for the first time and secondly on any postback activities like button click, dropdownlist selected index changed,gridview selected index changed etc. I am suspecting, in your page you have written the logic to bind the dropdown on page load. But, the problem is that when you are clicking on the button again the control goes to the page load event and as per your logic the dropdown is binding again, thus leaving the first element as selected after button click.

if you will use the above code the dropdown will be binded only on fresh load and not on any Postbacks.

Hope, it will help you.
If i am missing something or, your problem is still not resolved ..let me know.
If you problem is resolved then mark it as answer.

thanks !

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rsmc2011 on: 12/27/2011 [Member] Starter | Points: 25

Up
0
Down
You have to put the method for dropdown bind inside (!page.ispostbak).

Chandresh

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response