Trouble Implementing ASP.net Client Callback Feature

Last post 06-28-2007 12:39 PM by rmaiya. 5 replies.

Sort Posts:

  • Trouble Implementing ASP.net Client Callback Feature

    06-27-2007, 3:18 PM

    I am attempting to implement the ASP.NET 2.0's client callback feature.   My client side script looks similar to the following so far:

     

     function PrimeKeyCheck(sender, args)
    {
    var numberOfRecords=0;
    var hiddenField = document.getElementById("<%=NumOfRecordsHiddenField.ClientID%>");

    numberOfRecords = parseInt(hiddenField.value);
    if (numberOfRecords > 0)
    {
    args.IsValid = false;
    return;
    }

    args.IsValid = true;
    return;

    return ;
    }
     

    The server side function that I need to call is SalesmanManagerBLL.GetCountARNumber(). This function will access a database to retrieve the record count from a particular table. The problem I am having is that I don't know how to properly implement the ICallbackEventHandler and Page.GetCallbackEventReference for client callback. I have read through the article ASP.NET 2.0's Client Callback Feature, but I am still a little confused. Any suggestions?

    Fox
  • Re: Trouble Implementing ASP.net Client Callback Feature

    06-27-2007, 4:36 PM
    • Loading...
    • rmaiya
    • Joined on 06-25-2007, 11:08 PM
    • Olympia, WA
    • Posts 1,237

    Here is simple way of doing client callback

    on code behind side

    public string sCallBackFunctionInvocation;

    public string callbackArg;

    protected void Page_Load(object sender, EventArgs e)

    {

    lblMessage.Visible =
    false;

    if (!IsPostBack)

    sCallBackFunctionInvocation = Page.ClientScript.GetCallbackEventReference(this, "eventarg", "HandleResponse", "context", "PostBackError", true);

    }

    public void RaiseCallbackEvent(String eventArgument)

    {

    callbackArg = eventArgument;

    }

    public string GetCallbackResult()

    {

    // pass callbackArg

     SalesmanManagerBLL.GetCountARNumber().

    }

    On ASPX Side

    <script language="javascript" type="text/javascript">

    var textbox;

     

    function callServer(eventarg , context)

    {

    <%=sCallBackFunctionInvocation %>

    }

     

    function HandleResponse(eventarg , context)

    {

    alert(eventarg);

    }

    function PostBackError(eventarg , context)

    {

    alert(
    'Error Occured ' + eventarg + '\n' + context);

    }

    </script>

    Raghu
    (MCSD.NET, MCAD.NET, MCDBA)
    [Don't forget to click on Mark as answer on the post that helped you ]
  • Re: Trouble Implementing ASP.net Client Callback Feature

    06-27-2007, 5:50 PM

    So I what function would I call inside my script to get the result from  SalesmanManagerBLL.GetCountARNumber()

     

    Fox
  • Re: Trouble Implementing ASP.net Client Callback Feature

    06-27-2007, 8:16 PM
    • Loading...
    • rmaiya
    • Joined on 06-25-2007, 11:08 PM
    • Olympia, WA
    • Posts 1,237

    I dont know how u r trying to implement this. But my guess would be

    function PrimeKeyCheck()
     {

          var context; // dont worry about this right now, you need consider only event arg

           callServer(10 , context);
      }

    // In handle response from the server do  what ever u want;

    function HandleResponse(eventarg , context)
    {

     var numberofRecords = parseInt(eventarg);

    // do what ever you want with this integer value;

    }

    Raghu
    (MCSD.NET, MCAD.NET, MCDBA)
    [Don't forget to click on Mark as answer on the post that helped you ]
  • Re: Trouble Implementing ASP.net Client Callback Feature

    06-27-2007, 11:05 PM

     I am getting the following after implementing the suggested changes:

    The target '__Page' for the callback could not be found or did not implement ICallbackEventHandler.
    Fox
  • Re: Trouble Implementing ASP.net Client Callback Feature

    06-28-2007, 12:39 PM
    Answer
    • Loading...
    • rmaiya
    • Joined on 06-25-2007, 11:08 PM
    • Olympia, WA
    • Posts 1,237

    Looks like u didnt implemented ICallbackEventHandler interface. Your class should look like this

     

    public partial class ManageUsers : System.Web.UI.Page, ICallbackEventHandler

    {

    public string sCallBackFunctionInvocation;

    public string callbackArg;

    protected void Page_Load(object sender, EventArgs e)

    {

    if (!IsPostBack)sCallBackFunctionInvocation = Page.ClientScript.GetCallbackEventReference(this, "eventarg", "HandleResponse", "context", "PostBackError", true);

    }

    public void RaiseCallbackEvent(String eventArgument)

    {

    callbackArg = eventArgument;

    }

    public string GetCallbackResult()

    {

    switch (callbackArg)

    {

    // do u r method here

    }

    return "any string value u want return";

    }

     

    Raghu
    (MCSD.NET, MCAD.NET, MCDBA)
    [Don't forget to click on Mark as answer on the post that helped you ]
Page 1 of 1 (6 items)
Microsoft Communities
Page view counter