views:

265

answers:

2

I am using ASP.NET Callbacks (that implements the ICallbackEventHandler) and in the handler, I try to set a value of the text box:

txtName.text = "Test";

but this value is not set. Is this a limitation with callback? It appears I cannot do much in a callback handler other than sending back a string to the client side (ofcourse I can access the Session etc)

A: 

Even though you are calling back to the server, the whole page is not processed and sent back to the client. Thus, changes you make to controls server-side will not be reflected client-side.

Controls like the GridView uses callbacks in order to do some processing on the server while not incurring a full postback. Think of it as a form of AJAX. The GridView, upon receiving the string response you mention, is responsible for interpreting the string and updating its own state client-side using javascript.

Clarification: as described here:

the page...runs an abbreviated version of its normal life cycle to process the callback

so no, ASP.Net will not do a full page lifecycle, and no, no html will be returned to the client. Unless you return some html yourself in the GetCallbackResult method.

Idea: instead of doing callbackeventhandlers, take a look at JQuery with ASP.Net AJAX and more on the state of things here. This would enable your scenario with much of the plumbing already in place done by Microsoft.

Peter Lillevold
My understanding was a callback goes through the Page life cycle (A break point is hit in Page_Load). Does this mean, it skips the Page's Render method?
Thats correct. See my clarification. I see from your other comment that you want to bind a repeater: what you could do is return the data from the callback handler and then use e.g. JQuery to build up an html list client-side.
Peter Lillevold
Thanks. Do you happen to know which page methods are skipped during a callback?
Never mind. All methods after RaiseCallBackEvent are skipped. Thanks
That makes sense. ASP.Net would not need anything else from the page after the callback has been processed.
Peter Lillevold
A: 

I wouldn't call it a limitation, but it is not what ICallbackEventHandler was meant for. You could use an UpdatePanel if you wanted this functionality. If you want to stick with the ICallbackEventHandler approach, you could just return your string of text and then set the input client side.

Matt Dearing
Setting the textbox value was an example. I wanted to bind a repeater in the callback handler. Like Peter said, i think this is not possible as the page is not rerendered.
Right, what I am saying is there are several ways to do ajaxy calls from the client. You can use UpdatePanels, implement ICallbackEventHandler, use webservices, PageMethods, etc. They are all slightly different and each one has its own place based on your problem.
Matt Dearing