unable to Maintaining ViewState Across postbacks in a Usercontrol

U

Udit

I am writing a usercontrol that works as a years scheduler.This
usercontrol has some elements created at design time like 2 link
buttons to navigate years.
The calander is created dynamicaly by adding days at runtime using
HtmlControls.HtmlAnchor and i add its Server.Click event also at
runtime.
My problem is that the designtime controls work fine and are able to
maintain viewstate until i click any of the runtime controls which
destroys the entire viewstate and the ServerClick event of the Anchors
also fails to fire.
Any sugessions on this.
 
J

jeffpriz

Dynamically creating items is always a little bit tricky (well, more
tricky than design-time controls).

In the past when I've wanted to maintain viewstate-type information on
dynamically created controls I've manually added them to the page's
viewstate, and then manually pulled them back out on a postback and
re-applied them to the (now newly) re-created dynamic control.

If there's a better method I hope somebody would post information.. But
otherwise Viewstate.Add is your friend

jeffpriz
 
J

jeffpriz

ohh, and on the part about the ServerClick not firing, make sure that
you have re-created the control (the HtmlAnchor in this case) on the
postback BEFORE you exit the page_load.. otherwise there is no control,
and if there is no control, you can't have a ServerClick event, if that
makes any sense...

jeffpriz
 
U

Udit

Thanx for your reply.
I was able to make it work by creating controls with same id on every
post back and by calling this dynamic controls creation function on the
pageprerender event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top