Monday, March 26, 2012

newbie: My code crashes

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="http://links.10026.com/?link="><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.Find Control("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.Find Control("LinkToProfile");"

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

JeffThat 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.

Jeff wrote:

Quote:

Originally Posted by

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="http://links.10026.com/?link="><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.Find Control("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.Find Control("LinkToProfile");"
>
Any suggestions that may solve this problem are very welcome :-)
>
Jeff
>
>


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!
*************************************************
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23Pma5OmoGHA.5104@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

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="http://links.10026.com/?link="><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.Find Control("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.Find Control("LinkToProfile");"
>
Any suggestions that may solve this problem are very welcome :-)
>
Jeff
>
>


Thanks for the advice, I will try it.

"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@.comcast.netNoSpamMwrote in
message news:Oax8NlqoGHA.4960@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

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!
*************************************************
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23Pma5OmoGHA.5104@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

>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="http://links.10026.com/?link="><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.Find Control("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.Find Control("LinkToProfile");"
>>
>Any suggestions that may solve this problem are very welcome :-)
>>
>Jeff
>>
>>


>
>

0 comments:

Post a Comment