Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When we create link button Dynamically and add into placeholder ther error occur null reference exception was unhandled by user code please help me to solve this problem.

<linkbutton lbl="new" mode="hold"> lbl.Text = _NoticeBoardMaster[i].NOTICEHEADLINE + &quot;&lt;br
string NoticeId = _NoticeBoardMaster[i].NOTICEID.ToString();
lbl.ID = NoticeId;
lbl.ForeColor = System.Drawing.Color.SlateBlue;
lbl.Click += new System.EventHandler(lbl_Click);
PlaceHolder2.Controls.Add(lbl);
Posted

Please edit your posts, don't create new ones. Now I have to delete the old one.

Anything you create dynamically needs to be created before page load, if it's to have view state, and needs to be created on each postback, or it will be gone. Did you create it in the same postback that you ran this code ? What is <linkbutton lbl="new" mode="hold" /> ? It's not part of your code, nor anything useful if it's in an aspx.

This tells us you tried to access something. It doesn't tell us why you expect it to exist, where you called it, etc.
 
Share this answer
 
Comments
Pete O'Hanlon 1-Jul-11 8:43am    
My 5. Couldn't have put it better myself.
I'm going to guess that the problem lies in this line:
C#
_NoticeBoardMaster[i]
I suspect that whatever value of i you are using there, that there is no instance in _NoticeBoardMaster at that point. Put a breakpoint there and verify the value of this variable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900