By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

User control with dynamically created link buttons -- Issue

P: n/a
I'm have coded a simple menu (using link buttons as menu items) in a
user control to be reused across many ASPX pages.

In the page_load method I dynamically create the link buttons as
follows

LinkButton myLB = new LinkButton();
.........
.........

I put the above code inside a for loop so that many link buttons will
be created based on the number of elements in the array (and hence
forming my simple menu link that goes on top of each page).

The key point is that I have put the above mentioned logic in the
(!IsPostBack) block. The first time the page loads, eveything is fine.
But after a postback my screen looks empty.

If I remove the (!IsPostBack) block then everything works fine
(because all the code is executed whether its postback or not), which
I think is a perfromance issues and would like the state to be
preserved by asp.net.

Questions:
1. Just wondering whether ASP.NET will maintain viewstate when using
dynamically created controls in a user control?

2. If I implement the same functionality using custom controls
(instead of usr controls) then will viewstate will be preserved
automatically?

Thanks for your time....
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
One way to preserve content and state after a postback is to add the controls
to a Placeholder control.

"Gopal Krish" wrote:
I'm have coded a simple menu (using link buttons as menu items) in a
user control to be reused across many ASPX pages.

In the page_load method I dynamically create the link buttons as
follows

LinkButton myLB = new LinkButton();
.........
.........

I put the above code inside a for loop so that many link buttons will
be created based on the number of elements in the array (and hence
forming my simple menu link that goes on top of each page).

The key point is that I have put the above mentioned logic in the
(!IsPostBack) block. The first time the page loads, eveything is fine.
But after a postback my screen looks empty.

If I remove the (!IsPostBack) block then everything works fine
(because all the code is executed whether its postback or not), which
I think is a perfromance issues and would like the state to be
preserved by asp.net.

Questions:
1. Just wondering whether ASP.NET will maintain viewstate when using
dynamically created controls in a user control?

2. If I implement the same functionality using custom controls
(instead of usr controls) then will viewstate will be preserved
automatically?

Thanks for your time....

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.