473,657 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

panel's controls collection lost during postback

Hi,

I plan to use panel to store multiple HTML text in a web form page, here is
the code snippet that add HTML into panel:

Dim lit1 As New Literal
lit1.Text = strHTML
Panel1.Controls .Add(lit1)

The problem I have is , all literal controls I added into Panel1.Controls
are lost during the postback. Is there a way to overcome this?

I have another question somehow related to this one. How do I determine the
type at runtime, the following code snippet does not work:
If Panel1.Controls (i).GetType = LiteralConrol Then

TIA
Nov 18 '05 #1
3 3433
Hi.

You instantiate your Literal control and add it to the Page.Controls
collection only when it's not a post back, right? I.e. (C#):

if(!IsPostBack)
{
Literal lit1 = new ... blah blah
}

You shouldn't.
"Ed Chiu" <Ed****@discuss ions.microsoft. com> wrote in message
news:9B******** *************** ***********@mic rosoft.com...
Hi,

I plan to use panel to store multiple HTML text in a web form page, here
is
the code snippet that add HTML into panel:

Dim lit1 As New Literal
lit1.Text = strHTML
Panel1.Controls .Add(lit1)

The problem I have is , all literal controls I added into Panel1.Controls
are lost during the postback. Is there a way to overcome this?

I have another question somehow related to this one. How do I determine
the
type at runtime, the following code snippet does not work:
If Panel1.Controls (i).GetType = LiteralConrol Then

TIA

Nov 18 '05 #2
Thank you for the reply. But the answer is no.
The code snippet is not even in Page_load.

I have 2 buttons: btnSave and btnLoad

The code snippet is inside btnLoad_Click which is responsible for reading
infomation from SQL server and generate HTML texts per each record. This part
is working.

But btnSave_Click is not, when I click this button all controls in the panel
are lost. My guess is due to postback.



"Kikoz" wrote:
Hi.

You instantiate your Literal control and add it to the Page.Controls
collection only when it's not a post back, right? I.e. (C#):

if(!IsPostBack)
{
Literal lit1 = new ... blah blah
}

You shouldn't.
"Ed Chiu" <Ed****@discuss ions.microsoft. com> wrote in message
news:9B******** *************** ***********@mic rosoft.com...
Hi,

I plan to use panel to store multiple HTML text in a web form page, here
is
the code snippet that add HTML into panel:

Dim lit1 As New Literal
lit1.Text = strHTML
Panel1.Controls .Add(lit1)

The problem I have is , all literal controls I added into Panel1.Controls
are lost during the postback. Is there a way to overcome this?

I have another question somehow related to this one. How do I determine
the
type at runtime, the following code snippet does not work:
If Panel1.Controls (i).GetType = LiteralConrol Then

TIA


Nov 18 '05 #3
Sorry, at first I didn't realize you were talking about event handlers.
Of course, it's due to post back. If you new control(s) has not been in the
page when it first loaded and if they are not "global" to the page (not hard
coded in HTML, for example) and if you add them based on some condition(s)
while handling some post back event(s) your page is simply not aware of them
during Init event which happens every time. Meaning ViewState doesn't know
about them (if you use ViewState), etc.

What you do is the following: have a private method of your page class that
would create such control. Think about its correct implementation. And call
it from both handlers. Although generally bad idea, sometimes it's ok to use
ViewState, Cache or Session to store between post backs some key-value pairs
of vital properties of controls that have been added to container "on the
fly".

BTW, I forgot about your second question. The correct code would be (C#
again, sorry):

if(Panel1.Contr ols(i).GetType( ).Name.ToLower( ) == "literalconrol" )
{
// Blah blah
}

Kikoz

"Ed Chiu" <Ed****@discuss ions.microsoft. com> wrote in message
news:C6******** *************** ***********@mic rosoft.com...
Thank you for the reply. But the answer is no.
The code snippet is not even in Page_load.

I have 2 buttons: btnSave and btnLoad

The code snippet is inside btnLoad_Click which is responsible for reading
infomation from SQL server and generate HTML texts per each record. This
part
is working.

But btnSave_Click is not, when I click this button all controls in the
panel
are lost. My guess is due to postback.



"Kikoz" wrote:
Hi.

You instantiate your Literal control and add it to the Page.Controls
collection only when it's not a post back, right? I.e. (C#):

if(!IsPostBack)
{
Literal lit1 = new ... blah blah
}

You shouldn't.
"Ed Chiu" <Ed****@discuss ions.microsoft. com> wrote in message
news:9B******** *************** ***********@mic rosoft.com...
> Hi,
>
> I plan to use panel to store multiple HTML text in a web form page,
> here
> is
> the code snippet that add HTML into panel:
>
> Dim lit1 As New Literal
> lit1.Text = strHTML
> Panel1.Controls .Add(lit1)
>
> The problem I have is , all literal controls I added into
> Panel1.Controls
> are lost during the postback. Is there a way to overcome this?
>
> I have another question somehow related to this one. How do I determine
> the
> type at runtime, the following code snippet does not work:
> If Panel1.Controls (i).GetType = LiteralConrol Then
>
> TIA
>
>


Nov 18 '05 #4

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

Similar topics

2
4991
by: Sam | last post by:
I have a custom control (MyTextBox - taken from Microsoft website) that implements the IPostBackDataHandler interface. It is added to the controls collection of a placeholder control during the Page Load of a main ASPX page. Now if we debug the MyTextBox, we find the order of events like so (during a Posback, of course): OnInit -> OnLoad -> LoadPostData. My question is why does the LoadPostData occur *after* the OnLoad instead of...
5
6926
by: Robert Phillips | last post by:
I have a Panel control containing a few TextBox controls. The Panel is originally enabled, I enter data into the TextBox controls. When I submit, the Panel is disabled during the PostBack and the TextBox controls render greyed-out, and I can see the values in the TextBox controls....this is what I expected. I submit again, the Panel is enabled during the PostBack. All of the TextBox controls within the Panel are now enabled, however,...
1
2130
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new to programming, but I am new to ASP.NET and Web application design in general... loved the concept of user controls and dynamically adding them to a page. So what I wound up with was an application that dynamically loads two user controls directly...
1
3407
by: Marcus | last post by:
I have a problem maybe one of you could help me with. I've created a data entry screen with lots of dynamically-created client-side controls. I create HTML texboxes client-side by assigning a value to the td.innerHTML property. The UI is done, and I now want to post back the user's changes and update my business object in .NET. But when I postback, I can't see any of my dynamically created HTML controls in VB .NET. How do I make them...
4
2005
by: arun.hallan | last post by:
My code does the following... It references a stored procedure and builds a PlaceHolder containing certain controls, based on the parameters from the stored proc. This is implemented in it's own class. On the form, the user can select from a drop down box of many stored procs. From that, parameter fields are created which the user can change, in the PlaceHolder, and then added to the Panel on the form.
15
3612
by: mc | last post by:
I'm writing an app for managing Task Lists, I'm trying to add some controls to a form that I can use to link tasks, my original intention was to: - Add two list boxes, one listing "all Tasks" and the other listing "Linked Tasks", I have two buttons which in javascript move items from the first list into the second. Then when a user clicks a thrid button I would like to save this data.
8
5352
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In this code there is a panel panel1, that I populate with a lable in the foreground. Then when I click on "button1" a backgroundworker thread in async mode is started. When the backgoundworker thread completes the thread returns a panel to populate...
0
3113
by: wfsmith | last post by:
I have a page with a MultiView control and 6 Views. Each view has a User control that contains various form controls (dropdowns, textboxes and CascadingDropDown Ajax.Net controls). When the page is loaded, I populate the various form controls with data inside each of the 6 Views by accessing my exposed properties of my User Control. All the controls persist during postback, and any changes I make also persist during postbacks, but...
2
5706
by: =?Utf-8?B?TUNN?= | last post by:
I have an asp.net page that contains an update panel. Within the update panel, controls get added dynamically. During partial page post backs the controls within the panel will change. I have a javascript function that uses the ClientID of the dynamic controls to perform certain operations on the client-side. With each partial page post back, I dynamically recreate the javascript function using the ClientIDs of the newly added controls....
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.