Friday, March 16, 2012

persist values from one postback to another

Hi,

Not sure if the title makes sense but heres my dilemma. I have two
dropdownlist controls on a webform. I want to make sure that the first
dropdownlist control was clicked on and a value was selected. I want to check
in the second dropdownlist control that this has happened before processing
any info. I thought I would set a boolean in the selected event of the first
ddl control but when the event fires for the second ddl control the boolean
is set back to false due to the page reloading, I assume. How can I persist
that boolean value between postbacks? And for this scenario what is the best
way to achieve my goal if the way im describing is not the best?

Thanks,

JJTake a look at requiredFieldValidator and custom validator
The easiest way to handle this is to simply check and ensure the first
control is not set to index 0.

if(ddlFirstControl.SelectedIndex==0)
//code to indicate the user did not touch drop down 1
else
//code to process dropdown 2

If you want to persist a boolean (not necessary if the first drop down has
an invalid value, like "choose one"), you can store it in ViewState.

//in Drop down change event for the first drop down
ViewState("FirstControlChanged") = true;

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"JJ" wrote:

> Hi,
> Not sure if the title makes sense but heres my dilemma. I have two
> dropdownlist controls on a webform. I want to make sure that the first
> dropdownlist control was clicked on and a value was selected. I want to check
> in the second dropdownlist control that this has happened before processing
> any info. I thought I would set a boolean in the selected event of the first
> ddl control but when the event fires for the second ddl control the boolean
> is set back to false due to the page reloading, I assume. How can I persist
> that boolean value between postbacks? And for this scenario what is the best
> way to achieve my goal if the way im describing is not the best?
> Thanks,
> JJ

0 comments:

Post a Comment