开发者

Cannot set textbox value in Callback handler in asp.net

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 t开发者_JS百科his 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)


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜