Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ItemCreated FindControl problem c#

Reply
Thread Tools

ItemCreated FindControl problem c#

 
 
=?Utf-8?B?dHBhcmtzNjk=?=
Guest
Posts: n/a
 
      06-16-2005
All I need to do is set the border property of an image control to border=0.
I want to do this at runtime for the first image on the page in a datalist.
In the ItemCreated event I'm trying to use FindControl to set a reference to
the img control so I can change the attribute. But when I run the code below
I get the error: "Object reference not set to an instance of an object." I
assume its not finding the control and returning null? Anyway, you can see
what I'm trying to do, can anyone tell me how to get it to work? (code below)

******* code *******
public void main_ItemCreated(Object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
HtmlImage imgPatron = new HtmlImage();
imgPatron = (HtmlImage)e.Item.FindControl(Request.Form["patron"]);
if(imgPatron!=null)
{
image_count();
if(i_count == 1)
{
imgPatron.Border = 0;
}
}

}

************

Thanks for any help!
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      06-16-2005
Wrong event. I recommend using PreRender event since the page is fully built
at that stage. You can use ItemDataBound if you wish, but PreRender is
easier.

Eliyahu

"tparks69" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> All I need to do is set the border property of an image control to

border=0.
> I want to do this at runtime for the first image on the page in a

datalist.
> In the ItemCreated event I'm trying to use FindControl to set a reference

to
> the img control so I can change the attribute. But when I run the code

below
> I get the error: "Object reference not set to an instance of an object."

I
> assume its not finding the control and returning null? Anyway, you can

see
> what I'm trying to do, can anyone tell me how to get it to work? (code

below)
>
> ******* code *******
> public void main_ItemCreated(Object sender, DataListItemEventArgs e)
> {
> if (e.Item.ItemType == ListItemType.Item)
> {
> HtmlImage imgPatron = new HtmlImage();
> imgPatron = (HtmlImage)e.Item.FindControl(Request.Form["patron"]);
> if(imgPatron!=null)
> {
> image_count();
> if(i_count == 1)
> {
> imgPatron.Border = 0;
> }
> }
>
> }
>
> ************
>
> Thanks for any help!



 
Reply With Quote
 
 
 
 
=?Utf-8?B?QkVMSVVT?=
Guest
Posts: n/a
 
      06-16-2005
What is exactly the "Request.Form["patron"]"?

I think you should write:


.....FindControl(ID/name of the server side control);


Hope this help

"tparks69" wrote:

> All I need to do is set the border property of an image control to border=0.
> I want to do this at runtime for the first image on the page in a datalist.
> In the ItemCreated event I'm trying to use FindControl to set a reference to
> the img control so I can change the attribute. But when I run the code below
> I get the error: "Object reference not set to an instance of an object." I
> assume its not finding the control and returning null? Anyway, you can see
> what I'm trying to do, can anyone tell me how to get it to work? (code below)
>
> ******* code *******
> public void main_ItemCreated(Object sender, DataListItemEventArgs e)
> {
> if (e.Item.ItemType == ListItemType.Item)
> {
> HtmlImage imgPatron = new HtmlImage();
> imgPatron = (HtmlImage)e.Item.FindControl(Request.Form["patron"]);
> if(imgPatron!=null)
> {
> image_count();
> if(i_count == 1)
> {
> imgPatron.Border = 0;
> }
> }
>
> }
>
> ************
>
> Thanks for any help!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ItemCreated event problem =?Utf-8?B?dHBhcmtzNjk=?= ASP .Net 0 06-16-2005 05:02 AM
DataGrid Itemcreated Problem! Lars Netzel ASP .Net 1 12-09-2004 03:59 AM
DataList's ItemCreated event Hardy Wang ASP .Net 3 10-27-2003 09:39 PM
Re: getting column value in ItemCreated datagrid event Learning SQL Server ASP .Net 0 08-12-2003 01:38 PM
Why dropdown list created in ItemCreated can't selected lucy ASP .Net 0 08-05-2003 09:12 PM



Advertisments