Can I save an array in a hidden field?

I have an array of dropdownlist selections. For example array[0]= "Hello", array[1]="Bye".

I have a hidden field: <input id="test" runat="server" type="hidden" />

-- can i save that array in the hidden field, then grab the values AFTER the postback to the page?
If no, can I use a ViewState? i have a button, i click it, code rebinds to the grid but the ddl is OUTSIDE the rebinding code so it doesnt get re-bound. I want to save the values and stick them back in to ddl after the rebind..
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anurag ThakurTechnical ManagerCommented:
viewstate will be the best place to save it instead of a hidden field and you can definitely get them back and use them as you feel like later on the postback

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You could use String.Join to delimit the values into one long string and then Split the value on post back to get it back into an array.  Just need to use a suitable delimiter like |.
Anurag ThakurTechnical ManagerCommented:
string concatenation and splitting will incur an unnecessary overhead and we also know that strings are immutable
i will recommend to use array list and incur the boxing and unboxing overhead rather than using the string concatenation and splitting
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

There is also the serialization overhead of storing the object in ViewState, but I agree, string concatenation should be avoided if working on a large scale project.  I was merely providing a possible solution to storing the data in a hidden field.
CamilliaAuthor Commented:
>> viewstate will be the best place to save it instead of a hidden field
I just tried it and it worked. My coworker suggested a hidden field, Said ViewState wont work in what i'm trying to do.

Thanks. I will keep this open because i want to try something else with this viewstate. Thanks Kamila.
Anurag ThakurTechnical ManagerCommented:
-->> My coworker suggested a hidden field, Said ViewState wont work in what i'm trying to do.
can we know the reasons why your coworker said it wont work because in we normally dont use hidden fields now as often as a view state
hidden fields were more used in classic asp days
CamilliaAuthor Commented:
I said can I use "viewstate", he said "no, it wont work in this case". I think he just didnt know.
Let me try one thing with this viewstate and postback.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.