473,386 Members | 1,820 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,386 software developers and data experts.

DataLists ItemCreated question

I am trying understand when DataLists ItemCreated is called.

I put function that attaches a popup to my delete button:

Sub DataList_ItemCreated(Sender As Object, e As DataListItemEventArgs)
trace.warn("Inside DataList_ItemCreated Sender = " &
sender.GetType().tostring())
trace.warn("Itemtype = " & e.Item.ItemType & " " &
e.Item.ItemType.ToString())
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem,
ListItemType.EditItem
trace.warn(" Setting up myDeleteButton")
Dim myDeleteButton As LinkButton
myDeleteButton = e.Item.FindControl("btnDel")
if not myDeleteButton is nothing
myDeleteButton.Attributes.Add("onclick", "return confirm('Are you sure
you want to delete this question?');")
end if
End Select
trace.warn("leaving DataList_ItemCreated")
End Sub

But it seems to be called all over the place. In my trace I have the
following (I won't put all of them there), including the traces from the
above routine.

************************************************** ***************************
aspx.page Begin Init
aspx.page End Init
aspx.page Begin LoadViewState
Inside DataList_ItemCreated Sender = System.Web.UI.WebControls.DataList
Itemtype = 2 Item
Setting up myDeleteButton
leaving DataList_ItemCreated
Inside DataList_ItemCreated Sender = System.Web.UI.WebControls.DataList
Itemtype = 6 Separator
leaving DataList_ItemCreated
Inside DataList_ItemCreated Sender = System.Web.UI.WebControls.DataList
Itemtype = 3 AlternatingItem
Setting up myDeleteButton
leaving DataList_ItemCreated
....
aspx.page End LoadViewState
aspx.page Begin ProcessPostData
aspx.page End ProcessPostData
inside Page_load
aspx.page Begin ProcessPostData Second Try
aspx.page End ProcessPostData Second Try
aspx.page Begin Raise ChangedEvents
aspx.page End Raise ChangedEvents
aspx.page Begin Raise PostBackEvent
inside OnSelectIndex e.CommandName = Edit
inside DataListEdit
Inside DataList_ItemCreated Sender = System.Web.UI.WebControls.DataList
Itemtype = 2 Item
Setting up myDeleteButton
leaving DataList_ItemCreated
Inside DataList_ItemCreated Sender = System.Web.UI.WebControls.DataList
Itemtype = 6 Separator
leaving DataList_ItemCreated
Inside DataList_ItemCreated Sender = System.Web.UI.WebControls.DataList
Itemtype = 3 AlternatingItem
Setting up myDeleteButton
leaving DataList_ItemCreated
....
************************************************** *********

The same ones that are called in LoadViewState are also called in Raise
PostBackEvent. How do I tell which one is the delete button?

I found the problem when I ran this and tried to push the button on the left
of the delete button. It gave me an error that the object wasn't there. If
I push the delete button it works fine. I assume this is because it isn't
created yet. I get the error in the Raise PostBackEvent and not in the
LoadViewState.

At the moment, the button is being set up in the ListItemType.Item,
ListItemType.AlternatingItem and ListItemType.EditItem. Not sure why, but
that was how it was done in the example code I got this from.

I would like to only attach it once. I am not sure why this was done in
this event. I would think I could set it in the Page_load event (but maybe
not).

Thanks,

Tom
Nov 19 '05 #1
1 1496
On Mon, 14 Mar 2005 16:27:26 -0800, "tshad"
<ts**********@ftsolutions.com> wrote:
I am trying understand when DataLists ItemCreated is called.

I put function that attaches a popup to my delete button:


Tom:

Are you calling DataBind during the post back event? If so, I imagine
you are seeing ItemCreated fired once when the grid is restored from
ViewState, and once again when you data bind and recreate the grid.
Perhaps you'll want to attach to the ItemDataBound event, but I can't
tell for sure without digging into the code a little more.

--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #2

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

Similar topics

6
by: Jonathan Hollinger | last post by:
Very, very strange problem. In developing a C# ASP.NET application, every so often, DataLists disappear from the build. They remain visible and rendered (though sometimes dropping properties and...
1
by: Kevin Hector | last post by:
Hi. Can anyone explain why, when setting the Text of a Label control in the ItemCreated event of a Repeater (example below), the Text value is NOT persisted to ViewState? I know this can be fixed by...
1
by: Lars Netzel | last post by:
Hi! I'm so confused right now.. I have a Page that load a datagrid with a a bunch of radiobuttons in three columns which are then checkes or uncheck in the ItemCreated.(it's supposed to be a...
9
by: Manuel | last post by:
I have a Datagrid with 9 elements. The problem is that when I sort the grid by a column, it present more columns than there are. This is my code for the ItemCreated event: Private pNo As...
2
by: Nathan Sokalski | last post by:
I have a page on which I want to display several sections each of which contain a list of names. I have two database tables, one of which contains the section headings, and the other contains the...
3
by: Lars Netzel | last post by:
(applies to Windows Form .NET 2003) I'm filling a datagrid from a Datatable and applying a DataGridStyle. The Source Fields are "Name", "Value", "Locked" and the Style's Columns are "Name",...
2
by: Diffident | last post by:
Hello All, I have a question on datalists. I have 5 datalists on a page and when I try to view the "ViewSource", the value for the __VIEWSTATE is empty. How do datalists persist their values? ...
3
by: jason.gladstone | last post by:
Hello - I am trying to create a repeater control that contains a dropdownlist. A friend of mine sent me a sample in C#. I am trying to duplicate the sample in VB. This is the C# code in the...
2
by: Ole V.-M. | last post by:
Greetings, i have a UserControl, that contains a DataList. That DataList contains as items other DataLists. example: DataList A Row 1 Nested DataList 1 Row 1
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...

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.