Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating click event for control created on the fly

Status
Not open for further replies.

mjd3000

Programmer
Apr 11, 2009
136
GB
I am creating a control on the fly and then adding a click event to it. But I keep getting the error :

'The target 'ctl' for the callback could not be found or did not implement ICallbackEventHandler'

Here is my code related to the click event :

cht.Click += new ImageClickEventHandler(cht_Click);

protected void cht_Click(object sender, ImageClickEventArgs e)
{

}

I have googled this problem and found a suggestion that this can be solved by creating the click event in Page_Load, but this is not possible in this case. Is there any other way around this?
 
Sorry, but there isn't. Its' a limitation of the page lifecycle for webforms.

If using a link won't do what you want, then maybe you could use ajax to execute the operations that need to be carried out?

FWIW, there is a dedicated ASP.net forum:
Hope it helps,

Alex

[small]----signature below----[/small]
The author of the monograph, a native of Schenectady, New York, was said by some to have had the highest I.Q. of all the war criminals who were made to face a death by hanging. So it goes.

My Crummy Web Page
 
web or win forms? I don't design winforms, but webforms you can dynamically define controls to render to the client. There are some pitfalls and gotchas that you need to know, but it is possible. This is all documented on the net. search for dynamically add button to webform.

the main points are
1. the control should be instantiated and added to the webform in the Page_Init event.
2. The control should be assigned an ID so viewstate/control state will work properly.
3. The control must be created/added every time (no checking for ispostback)

there may be a few others, it's been awhile since I used webforms, but that's the bulk of it.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top