Hi,
Yes. NopCommerce uses similar technique at other places too such as, on admin dashboard you can see different collapsible panes. When you collapse a pane and go back to dashboard again, nopCommerce remembers that you have collapsed / not collapsed a pane and displays it accordingly.
You can see it in below explanation on how it works for panes. Let's talk about news pane:
Go to this page in code: \Presentation\Nop.Web\Areas\Admin\Views\Shared\Components\NopCommerceNews\Default.cshtml
At line number 8, 9 and 10 you can see following code which reads current setting for a pane from database:
const string panelId = "nopcommerce-news-box";
const string hidePanelAttributeName = "HideNopCommerceNewsPanel";
var hidePanel = genericAttributeService.GetAttribute<bool>(workContext.CurrentCustomer, hidePanelAttributeName);
Now, at line number 13 you can see following code that set's css property based on condition:
<div class="box box-info @if(hidePanel){<text>collapsed-box</text>}" id="@panelId">
I hope this gives you a proper answer on how you can achieve what you asked using some tweaks in your code. Let me know if you have any more queries regarding this.
Thank you,
Atul