Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 553 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is a callback?

#1
What's a callback and how is it implemented in C#?
Reply

#2
A callback is a function pointer that you pass in to another function. The function you are calling will 'callback' (execute) the other function when it has completed.

Check out [this][1] link.


[1]:

[To see links please register here]

Reply

#3
Probably not the dictionary definition, but a callback usually refers to a function, which is external to a particular object, being stored and then called upon a specific event.

An example might be when a UI button is created, it stores a reference to a function which performs an action. The action is handled by a different part of the code but when the button is pressed, the callback is called and this invokes the action to perform.

C#, rather than use the term 'callback' uses 'events' and 'delegates' and you can find out more about delegates [here][1].


[1]:

[To see links please register here]

Reply

#4
**If you referring to ASP.Net callbacks:**

> In the default model for ASP.NET Web
> pages, the user interacts with a page
> and clicks a button or performs some
> other action that results in a
> postback. The page and its controls
> are re-created, the page code runs on
> the server, and a new version of the
> page is rendered to the browser.
> However, in some situations, it is
> useful to run server code from the
> client without performing a postback.
> If the client script in the page is
> maintaining some state information
> (for example, local variable values),
> posting the page and getting a new
> copy of it destroys that state.
> Additionally, page postbacks introduce
> processing overhead that can decrease
> performance and force the user to wait
> for the page to be processed and
> re-created.
>
> To avoid losing client state and not
> incur the processing overhead of a
> server roundtrip, you can code an
> ASP.NET Web page so that it can
> perform client callbacks. In a client
> callback, a client-script function
> sends a request to an ASP.NET Web
> page. The Web page runs a modified
> version of its normal life cycle. 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.
> Throughout this process, the page is
> live in the browser.

Source:

[To see links please register here]


**If you are referring to callbacks in code:**

Callbacks are often delegates to methods that are called when the specific operation has completed or performs a sub-action. You'll often find them in asynchronous operations. It is a programming principle that you can find in almost every coding language.

More info here:

[To see links please register here]

Reply

#5
callback work steps:


1) we have to implement `ICallbackEventHandler` Interface


2) Register the client script :



String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
String callbackScript = "function UseCallBack(arg, context)" + "{ " + cbReference + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallBack", callbackScript, true);


1) from UI call Onclient click call javascript function for EX:- `builpopup(p1,p2,p3...)`


var finalfield= p1,p2,p3;
`UseCallBack(finalfield, "");` data from the client passed to server side by using UseCallBack


2) `public void RaiseCallbackEvent(string eventArgument)` In eventArgument we get the passed data
//do some server side operation and passed to "callbackResult"


3) `GetCallbackResult()` // using this method data will be passed to client(ReceiveServerData() function) side


callbackResult

4) Get the data at client side:
`ReceiveServerData(text)` , in text server response , we wil get.
Reply

#6
Definition
==
> A **callback** is executable code that
> is passed as an argument to other code.

Implementation
==

// Parent can Read
public class Parent
{
public string Read(){ /*reads here*/ };
}

// Child need Info
public class Child
{
private string information;
// declare a Delegate
delegate string GetInfo();
// use an instance of the declared Delegate
public GetInfo GetMeInformation;

public void ObtainInfo()
{
// Child will use the Parent capabilities via the Delegate
information = GetMeInformation();
}
}

Usage
==

Parent Peter = new Parent();
Child Johny = new Child();

// Tell Johny from where to obtain info
Johny.GetMeInformation = Peter.Read;

Johny.ObtainInfo(); // here Johny 'asks' Peter to read


**Links**

- [more details][2] for C#.

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through