Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7445985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:11:20+00:00 2026-05-29T12:11:20+00:00

Maybe someone can help me out. I have created a simple web user control,

  • 0

Maybe someone can help me out. I have created a simple web user control, a date and time picker, to be dropped onto my webform. This all works very nicely, I can set properties, usee the control satisfactorily for ui etc.

When it comes time to “use” the controls selected_date_time property, I just cant get it to persist. Nothing.. I have researched and tried endlessly using viewsate, context and session. Onbiouosly session works, but its dirty, and I am using two copies of this control (start and end time), so session vars really needs to be hacked to maket his work.

Am I missing something? The control gets initialized every time something happens, and obviuosly loses its state information. The ui keeps its state tho, as I can select a date, write that date to a label, and that persists. But when I try to access my properties of the control to retreive the selected combined date and time, (that is already persisting visually), its nothing. I debuggeed and it gets initialized everytime I do any form of post on the page.

Can someone please shed some light on this for me? Its really starting to be an issue now.

Thanks in advance.

Example: (simple components)

UC _ save_method

ViewState("var_time") = "My veiwstate text"

form _read_method

dim str as string = ViewState("var_time")

form sees nothing in the viewstate var.

I have also tried it with normal properties and values, which wasn’t working, which is why I moved on to viewsate var’s for my properties. Right now, I am just trying to get the viewstate to work even without properties.

Seems my form and the control must have two seperate viewstates? I am a bit of a n00b concerning viewstates.

Thanks

[solution]
You have to explicitly reset your properties on the prerender method of the control. My misunderstanding was that the page and the control share the same single viewstate. Turns out the control and the page that its on, has its own independant viewstates.

So absically, on your property set function in the control, set your value in the viewstate, and upon prerender, take that viewstate value, and set the property get variable =- the value in viewstate.

You can now access the property from your page as if everything was normal and the world is not ending… pheww

Thanks to cnay for directing me.


'Usr control xyz

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

my_time = ViewState("var_time")
'my_time is the get variable for property date_time

End Sub

'page use

xyz.date_time

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:11:20+00:00Added an answer on May 29, 2026 at 12:11 pm

    Perhaps, you should post the complete control code to get the better answer but speaking in general terms – view-state (or control state) is a typically correct approach to persists control state such as properties. Each control instance get the different view-state bag and hence collisions are easily avoided.

    Now, coming to your problem, a typical editable control first restores its state from view-state and then uses the request data to modify the state as needed. For example, a simple text-box control would persists its text value in view-state. On post-back, the text value will be restored from the view-state and then gets overwritten by the value present in the request (looked up by UniqueID property).

    Now, for user controls, typically you can use child controls values (or properties) to derive the control value/properties – so these may not use view-state. However, if you add properties/state that is not backup by child controls then you may have to back them up in the view-state. So let’s say your user control has two child controls – one for Date and other for time then can combine their values to get the selected date-time value for your control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, the specs have changed on this one somewhat. Maybe someone can help me
Hi maybe someone can help me here ... I have a slight problem with
I'm going slidely mad over here, maybe someone can help me figure out what's
Maybe there's someone out in the ether that can help me with this one.
I really hope someone can help on this because I'm learning cocoa and have
I would like to know some way to do this, maybe someone can help
I'm just stuck with a problem (maybe Simple). But I can't figure out how
I'm having trouble groking something in Linq - maybe someone can give me some
I'm a Linq noobie, maybe someone can point me in the right direction. What's
I am writing my first FireFox extension and I have some questions. Maybe someone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.