473,385 Members | 1,465 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,385 software developers and data experts.

User Control Disappears After PostBack - Why?

I have a simple user control (see below) that has EnableViewState="true". I
place it on an ASPX page at runtime using a PlaceHolder - which also has
EnableViewState="true".

After a postback, the aspx page renders back to the client, but the user
control is not on the rendered page. Why? I thought ViewState was supposed
to keep things intact between postbacks. FWIW: during the postback the code
does nothing with respect to the user control or to the PlaceHolder within
which it resides. Additonally, the hosting aspx page has a few WebControls
(TextBox, DropDownLists, etc..) and they retain their respective values
between postbacks as expected. What's the deal with the user control?

<%@ Control EnableViewState="true" %>
<table>
<tr>
<td>
This text is in a table in the user control
</td>
</tr>
</table>

Thanks!

-GH
Nov 18 '05 #1
3 16059
If you dynamically add a Control to the page during a single Request, be
aware that every PostBack is a new Request. ViewState has nothing to do with
it. You need to add the Control with each PostBack. HTTP is stateless.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Guadala Harry" <gm**@hman.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
I have a simple user control (see below) that has EnableViewState="true". I place it on an ASPX page at runtime using a PlaceHolder - which also has
EnableViewState="true".

After a postback, the aspx page renders back to the client, but the user
control is not on the rendered page. Why? I thought ViewState was supposed
to keep things intact between postbacks. FWIW: during the postback the code does nothing with respect to the user control or to the PlaceHolder within
which it resides. Additonally, the hosting aspx page has a few WebControls
(TextBox, DropDownLists, etc..) and they retain their respective values
between postbacks as expected. What's the deal with the user control?

<%@ Control EnableViewState="true" %>
<table>
<tr>
<td>
This text is in a table in the user control
</td>
</tr>
</table>

Thanks!

-GH

Nov 18 '05 #2
"Guadala Harry" <gm**@hman.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
I have a simple user control (see below) that has EnableViewState="true". I place it on an ASPX page at runtime using a PlaceHolder - which also has
EnableViewState="true".

After a postback, the aspx page renders back to the client, but the user
control is not on the rendered page. Why? I thought ViewState was supposed
to keep things intact between postbacks. FWIW: during the postback the code does nothing with respect to the user control or to the PlaceHolder within
which it resides. Additonally, the hosting aspx page has a few WebControls
(TextBox, DropDownLists, etc..) and they retain their respective values
between postbacks as expected. What's the deal with the user control?

<%@ Control EnableViewState="true" %>
<table>
<tr>
<td>
This text is in a table in the user control
</td>
</tr>
</table>

Thanks!

-GH


Didn't you get an answer to this already?

Oh, well, in case I'm thinking of some other question, the answer is that
you have to load dynamic controls on ALL page requests, not just the initial
request. You also need to load them in the same order each time if any of
them use ViewState. So, for instance:

private void Page_Load(object sender, EventArgs e)
{
// Dynamically load the control, then:
if (!Page.IsPostBack)
{
// Do dynamic initialization of controls which need such
initialization only once
}
}
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #3
Thanks John and Kevin

-GH

"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:ua*************@TK2MSFTNGP10.phx.gbl...
"Guadala Harry" <gm**@hman.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
I have a simple user control (see below) that has EnableViewState="true".
I
place it on an ASPX page at runtime using a PlaceHolder - which also has
EnableViewState="true".

After a postback, the aspx page renders back to the client, but the user
control is not on the rendered page. Why? I thought ViewState was
supposed to keep things intact between postbacks. FWIW: during the postback the

code
does nothing with respect to the user control or to the PlaceHolder within which it resides. Additonally, the hosting aspx page has a few WebControls (TextBox, DropDownLists, etc..) and they retain their respective values
between postbacks as expected. What's the deal with the user control?

<%@ Control EnableViewState="true" %>
<table>
<tr>
<td>
This text is in a table in the user control
</td>
</tr>
</table>

Thanks!

-GH


Didn't you get an answer to this already?

Oh, well, in case I'm thinking of some other question, the answer is that
you have to load dynamic controls on ALL page requests, not just the

initial request. You also need to load them in the same order each time if any of
them use ViewState. So, for instance:

private void Page_Load(object sender, EventArgs e)
{
// Dynamically load the control, then:
if (!Page.IsPostBack)
{
// Do dynamic initialization of controls which need such
initialization only once
}
}
--
John Saunders
johnwsaundersiii at hotmail

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Yan Wang | last post by:
Hi!: I encounter this problem when I do some tests: I have one user control with datalist in it. The ID for datalist is "dlTest". Then in this control code behind class, I declare a protected...
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
7
by: moondaddy | last post by:
I'm building a page in vb.net with several user controls on it. I'm using user controls instead of a frames page since I've seen this recommended many times in this user group. I want just one of...
1
by: Troy | last post by:
I'm sure i've clobbered something, even though I have recreated the control from scratch I add a UserControl to a for Test the form, it works fin stop the debugger open the form designer the...
2
by: Chris Veal | last post by:
I created a user control and drag it onto a Winform I run the app OK but when I return to the dev environment the user control disappears Has anyone seen this b4? Whats the deal with that? ...
2
by: Nemo | last post by:
Hi, I have i fishy problem when I have e Repeater with user controls. page_load { if (!isPostBack) { repeater.databind(); }
9
by: Chris | last post by:
I am dynamically adding a user control to each row in a gridview. The reason I am doing it dynamically is the user control is different depending on certain data in the gridview. The gridview...
0
by: MikeB | last post by:
Hello All, I have UserControl that consists of a Menu control. When a user selects an item in the Menu I set a Public variable in the MenuItemClick event. My problem is that when the main...
0
by: dethadi | last post by:
Hi: I am loading a user control on postback of a link click event. Now, when I try to retrieve the selected values in this control on button click event (next postback), I am not able to. Can you...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.