newbie: My code crashes

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

hey

asp.net 2.0

I'm trying to make a webpage that shows a list of pictures. When the user
clicks on a picture, the user is redirected to another page in my website.
The links are generated at runtime

My code crashes during runtime because of a variable in the ItemDataBound
event is null. Below I show my problem code and maybe some of you could give
me a suggestion to what should do to fix this...


<td rowspan="2"><a id="LinkToProfile" href=""><asp:Image ID="MemberPhoto"
runat="server" ImageAlign="Left" /></a></td>

System.Web.UI.HtmlControls.HtmlAnchor link = null;
link =
(System.Web.UI.HtmlControls.HtmlAnchor)e.Item.FindControl("LinkToProfile");
link.HRef = "../test.aspx?id=" + subscriber.UserName;

My code crashes because the variable "link" is null after this line "link =
(System.Web.UI.HtmlControls.HtmlAnchor)e.Item.FindControl("LinkToProfile");"

Any suggestions that may solve this problem are very welcome :-)

Jeff
 
That is because there is no control with the id "LinkToProfile". You
have to put runat="server" in the tag to make it a server control.
 
Why not dynamically generated ImageButtons and set the image and postbackUrl
on the control to do what you desire. You can then have complete control
without a lot of code and use a control that is designed to do both of the
tasks you desire.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
Thanks for the advice, I will try it.




Cowboy (Gregory A. Beamer) said:
Why not dynamically generated ImageButtons and set the image and
postbackUrl on the control to do what you desire. You can then have
complete control without a lot of code and use a control that is designed
to do both of the tasks you desire.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top