473,387 Members | 3,801 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,387 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 5590
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ryan Ternier | last post by:
Hello, I have a repeater control that does the following on the ItemDataBound event. It works perfectly, except that when it prints out, the names of the controls aren't what I'd expect. ...
3
by: Shawn H. Mesiatowsky | last post by:
I have an array list that I want to display to the browser. I need very precise control of the repeater, so I have function for the OnItemDataBound event for the repater, then in that function I...
7
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the...
1
by: keith.walter | last post by:
My first asp.net app is almost "done" and I am stuck. Here is my situation: I have a "mother" page add_customer.aspx and a"child" user control add_group.ascx. On the mother page is an "add...
5
by: Doug Handler | last post by:
Hi, I have a form (Form1) that contains a tab control which one tab has a customer user control (UserControl1). When the user double-clicks on the grid hosted there a new user control is...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
2
by: glenn | last post by:
Hi folks, I am trying to determine which item in a DropDownList Web control has been selected. I have posted an OnSelectedIndexChanged subroutine in my code with a reference to the subroutine...
8
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
1
by: shapper | last post by:
Hello, I have a class where I created various controls. One of the controls have a property which is a generic list of WebControl. Then in web site page I have something like: Dim a As New...
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: 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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.