Click here to Skip to main content
15,914,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using dropdwonlist for getting YES or NO from user and take the action in button click event but it always gives default value NO. I am using masterpage with update panel. So what to do to keep the user selected value?

aspx.cs page:

protected void btnSubmit_Click(object sender, EventArgs e)
{
if(DropDownList1.SelectedValue.ToString() == "YES")
{

//BODY PART
}
}
Posted
Updated 12-Jan-10 18:52pm
v2

Reason is:
Before the execution of the button click event, the dropdown is getting re-bind again.

Please keep the dropdown databind lines of code inside an if condition that can handle the full postback or asynchronous postback (this will depend if you have kept dropdown and the button both or one inside the update panel)

You can use two properties of page for the same:
IsAsyncPostBack & IsPostBack to track it.

Sandeep
 
Share this answer
 
There could be 2 posibilities
1. You have added the items on page load event without checking condition "not postback"
2. May be the value of both the items would be same "Yes".

Can you post your master page files (aspx and cs), page files(aspx and cs) code to identify your problem?

Thanks
Mehul Thakkar
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900