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
>
>