471,317 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Control.Add or Item.Add

I am new to ASP.NET and am becoming frustrated.

I am able to add items to a drop-down list box (SELECT) and the items remain
across server calls. When I add controls to a DIV (or to the Form for that
matter) they are not retained. When I add HTML from the server using the
InnerHtml property of the DIV (a Generic Html control) the state is
maintained. What is the difference between InnerHtml += <img etc. > and
Controls.Add(new HtmlImage())? Why does one persist and the other not.

Thanks in advance.

David
Dec 18 '05 #1
2 5536
Hi David,

The HtmlGenericControl stores its InnerHtml in ViewState. This is why it
persists. When you add a Control to it, you are not persisting that Control
in any way. The next PostBack, it's not there, because it wasn't persisted,
and you didn't re-add it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"David" <Co*********@AdsorptionProcessModeling.com> wrote in message
news:c5ipf.41801$WH.1753@dukeread01...
I am new to ASP.NET and am becoming frustrated.

I am able to add items to a drop-down list box (SELECT) and the items
remain across server calls. When I add controls to a DIV (or to the Form
for that matter) they are not retained. When I add HTML from the server
using the InnerHtml property of the DIV (a Generic Html control) the state
is maintained. What is the difference between InnerHtml += <img etc. >
and Controls.Add(new HtmlImage())? Why does one persist and the other
not.

Thanks in advance.

David

Dec 18 '05 #2

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
Hi David,

The HtmlGenericControl stores its InnerHtml in ViewState. This is why it
persists. When you add a Control to it, you are not persisting that
Control in any way. The next PostBack, it's not there, because it wasn't
persisted, and you didn't re-add it.
Thank you. But how can I get it to persist?

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"David" <Co*********@AdsorptionProcessModeling.com> wrote in message
news:c5ipf.41801$WH.1753@dukeread01...
I am new to ASP.NET and am becoming frustrated.

I am able to add items to a drop-down list box (SELECT) and the items
remain across server calls. When I add controls to a DIV (or to the Form
for that matter) they are not retained. When I add HTML from the server
using the InnerHtml property of the DIV (a Generic Html control) the
state is maintained. What is the difference between InnerHtml += <img
etc. > and Controls.Add(new HtmlImage())? Why does one persist and the
other not.

Thanks in advance.

David


Dec 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ryan Ternier | last post: by
3 posts views Thread by Shawn H. Mesiatowsky | last post: by
7 posts views Thread by charliewest | last post: by
5 posts views Thread by Doug Handler | last post: by
1 post views Thread by shapper | last post: by
reply views Thread by rosydwin | last post: by

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.