Hi Dave,
In a client callback, a client script function sends a request to the
ASP.NET Web page, which then runs an abbreviated version of its normal life
cycle to process the callback: the page is initiated and its controls and
other members are created, and then a specially marked method is invoked.
The method performs the processing that you have coded and then returns a
value to the browser that can be read by another client script function.
Besides implementing ICallbackEventHandler and its methods
RaiseCallbackEvent, GetCallbackResult, the page must contain three client
script functions that perform the following actions:
* One function calls a helper method that performs the actual request to
the server. In this function, you can perform custom logic to prepare the
event arguments first, and then you can send a string as a parameter to the
server-side callback event handler.
* Another function receives (is called by) the result from the server code
that processed the callback event, accepting a string that represents the
results. This is called the client callback function.
* A third function is the helper function that performs the actual request
to the server, which is generated automatically by ASP.NET when you
generate a reference to this function using the GetCallbackEventReference
method in server code.
The key point here is that it's not a postback, the page will not be
rendered again; if you change the server-side controls' properties, the
changes will not be rendered.
Therefore, in your code, if we make following changes:
(In MyControl)
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//Page.ClientScript.RegisterClientScriptBlock(typeof(MyControl),
"OnSuccess", "function OnSuccess(result, context) { }", true);
string callback =
Page.ClientScript.GetCallbackEventReference(this, "result",
string.Concat(ID, "OnSuccess"), "context");
Page.ClientScript.RegisterClientScriptBlock(typeof(MyControl),
ID, string.Concat("function ", ID, "Callback(result, context) { ",
callback, "; }"), true);
}
(In ASPX)
<head>
<title>Test Page</title>
<script language="javascript" type="text/javascript">
function MyControl1OnSuccess(text) {
alert(text);
}
</script>
</head>
References:
#Implementing Client Callbacks Without Postbacks in ASP.NET Web Pages
http://msdn2.microsoft.com/en-us/library/ms178208.aspx #Client-Callback Implementation (C#) Example
http://msdn2.microsoft.com/en-us/library/ms178210.aspx Sincerely,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document:
http://blogs.msdn.com/msdnts/pages/postingAlias.aspx Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.