Custom ASP.Net Server Control Issue

I have a asp.net server control that I have written, that display a ordered or unordered list that can contain a number of list items. The developer can determine the through properties to set the number of initial items to display when the controls are invoked the firstime on the web form. For example, there are 10 items, the developer says 5 should show and 5 should remain hidden.

When rendered, there are two buttons that allow the vistor to make these items appear or hide items one click at a time buy the use of client side JavaScript.

The issue is, when the page refreshes, because of the current design, the controls revert back to their initial items to display property.

I'm struggling with the best way to handle some sort of viewstate that the pages remembers the last number of items the user had exposed before the page refreshed or when they return back to it. The other thing to consider is that the list can also be a static text or even a hyperlinked list of items.

So I need to figure out how to communicate the present items count back to the control so when it redisplays the same number.

I've thought about a hidden field that the JavaScript routine would update (+ or -), cookies ro some other method. I don't believe there is anyway to use the viewstate for this, but could be wrong.

Any thoughts on how this should be handled in the real world asp.net server control?
LVL 1
WebGeeksUnlimitedAsked:
Who is Participating?
 
ASPSQLServerCOMConnect With a Mentor Commented:
http://www.eggheadcafe.com/articles/20030625.asp

you have to use
protected override object SaveViewState()
and protected override void LoadViewState(object savedState)
0
 
Obadiah ChristopherCommented:
When u r updating using javascript the best would be to update a hidden field...

And fetch the details from the hidden field when the page posts back
0
 
WebGeeksUnlimitedAuthor Commented:
I was thinking of that, but that would only work if you post back to the same page. It's possible that the link could take you to a different page on the site, which at that point, you would loose that current items displayed count.
 
0
 
WebGeeksUnlimitedAuthor Commented:
I wasn't sure that this would work originally, but I'll read the article over the weekend and give it a try.
0
 
WebGeeksUnlimitedAuthor Commented:
This does the trick ... Thx :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.