473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

User control with dynamically created link buttons -- Issue

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
1 2564
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David J. Berman | last post by:
Thanks for any help...! My error is: Object reference not set to an instance of an object. > public int DisplayOrder { > get { >>>>>> return (int) ViewState; > }
5
by: Jonah Olsson | last post by:
Hello guys, I have an application which is built upon several user controls. That is, I have a default template (default.aspx) that I load a user control into (using placeholders in the...
1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
0
by: Jason Chancellor | last post by:
Fairly new to asp.net so I'm sure what I'm doing wrong is silly... I have created a user control which contains its own buttons, textboxes, etc... and handles its own events. If I add just one...
6
by: Louise | last post by:
I use Visual Basic .NET Framework 1.1, Visual Studio. I have a Web page (aspx) referencing a control (ascx) that has a placeholder that is assigned one of 2 child controls through buttons. The...
1
by: Landley | last post by:
Hi Everyone, I have created a user control that contains two buttons. The buttons have been created using <asp:Button> tag. I have then created another user control that contains an...
1
by: Ryan Ternier | last post by:
I'm playing around with a user control that I think might help one of my projects. I'm having an issue with it retaining the controls inside a placeholder that are added dynamically. Here's the...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
2
by: ccbalapatel | last post by:
Hi, We have recently converted our code to ASP.NET 2.0. We have an user control that is embedded inside the page. The user control has a link button and the event handler for the link button is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.