?
Solved

Can I save an array in a hidden field?

Posted on 2008-11-12
7
Medium Priority
?
2,046 Views
Last Modified: 2012-05-05
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..
0
Comment
Question by:Camillia
  • 3
  • 2
  • 2
7 Comments
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 1600 total points
ID: 22941592
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
0
 
LVL 8

Expert Comment

by:OBonio
ID: 22941603
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 |.
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22941751
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Assisted Solution

by:OBonio
OBonio earned 400 total points
ID: 22941855
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.
0
 
LVL 7

Author Comment

by:Camillia
ID: 22942012
>> 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.
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22942371
-->> 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 asp.net we normally dont use hidden fields now as often as a view state
hidden fields were more used in classic asp days
0
 
LVL 7

Author Comment

by:Camillia
ID: 22942988
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.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Integration Management Part 2
Loops Section Overview
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question