473,385 Members | 2,069 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.

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 3411
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****@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.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****@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.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.Controls(i).GetType().Name.ToLower() == "literalconrol")
{
// Blah blah
}

Kikoz

"Ed Chiu" <Ed****@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.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****@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.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
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...
5
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...
1
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...
1
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...
4
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...
15
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"...
8
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...
0
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.