Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2004, 12:33 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default User Control addition to header template

I am currently working with a user control - it is functioning as designed. I am trying to add an image button to it, and I am getting the error, "Object reference not set to an instance of an object".

I am using VS.NET, and made sure that the line
Code:
Protected WithEvents imbHeader As System.Web.UI.WebControls.ImageButton
was included in the codebehind.

This User Control's main purpose is to house a datalist. What I am trying to do is put an Image Button in the header template, so that I can set it's imageURL property dynamically. Is there a conflict wherein I can't place another control into a datalist?

Thanks in advance
Colonel

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old February 26th, 2004, 12:40 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Update: The forms designer tells me that a component already has the name "imbHeader". This is not the case.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old February 26th, 2004, 01:43 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

When you place controls within a control like a datalist, you often have to handle things a bit differently.

In the page code, you need to create a handler for the DataList.ItemCreated event. ItemCreated fires after each row item of the datalist is created so you need to test for the appropriate datalist item. Then you can search for and cast the image button control and set the ImageUrl property on it.

Private Sub oDataList_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles oDataList.ItemCreated
    If e.Item.ItemType = ListItemType.Header Then
        CType(e.Item.FindControl("imbHeader"), ImageButton).ImageUrl = "..."
    End If
End Sub

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Word WITH Template or Header Graphic Ron Howerton ASP.NET 2.0 Professional 1 October 31st, 2007 03:18 PM
DropDownList in Header of GridView Control ... [email protected] ASP.NET 2.0 Professional 0 December 5th, 2006 12:20 AM
User object in Master Page template? lancer ASP.NET 2.0 Basics 0 June 22nd, 2006 01:32 PM
Freezing Column and Header in DataGrid Control pramesh_it ASP.NET 1.0 and 1.1 Basics 0 April 3rd, 2006 05:54 AM
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.