question

RamaKrishnaboyina-9136 avatar image
0 Votes"
RamaKrishnaboyina-9136 asked YijingSun-MSFT answered

GetCallbackEventReference is not working correctly

I have a small web application using ASP.NET.
I have implemented GetCallbackEventReference as follows

CallBackTest.aspx.cs:-

public partial class CallBackTest : System.Web.UI.Page,ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
Initialize();
}

     public void Initialize()
     {
         mObcButton.Attributes["onclick"] = base.Page.ClientScript.GetCallbackEventReference(
             // control to handle callback on the server
                                                 this,
             // from client
             // add "R" to string to denote On Demand Read button/callback
                                                 String.Format("\"{0}|{1}|{2}|{3}\"", "R", "73659627", "121", "1"),
             // browser callback function
                                                 "obcCallback",
             // context directly from us for callback function
                                                  mObcButton.ClientID)
                                                  + "; obcRequested(" + mObcButton.ClientID + ")";

     }

     public void RaiseCallbackEvent(String eventArgument)
     {
         // Processes a callback event on the server using the event
         // argument from the client.
     }

     public string GetCallbackResult()
     {
         // Returns the results of a callback event to the client.
         string dateString = DateTime.Now.ToLongDateString();

         return dateString;
     }
        
 }

CallBackTest.aspx:-

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CallBackTest.aspx.cs" Inherits="GetCallBackDemo2.CallBackTest" %>

<html xmlns="http://www.w3.org/1999/xhtml">;
<head runat="server">
<title></title>

</head>
<body>
<table class="properties" width="100%">
<tr>
<td class="propertiesLabel" style="height: 26px; width: 31%">On Demand

         <br />
             Consumption Read:</td>
         <td class="propertiesValueWrap" style="height: 26px">
             <input id="mObcButton" runat="server" class="button" name="mOdrButton" type="button" style="padding: 2px"
                 value="Read..." onclick="obcRequested(this)" />

         </td>
     </tr>
     <tr>
         <td class="propertiesLabel">Status:</td>
         <td id="odrStatus" class="propertiesValueWrap">
             <asp:Literal ID="mObcStatusText" runat="server" />
         </td>
     </tr>
 </table>

</body>

<script type="text/javascript">

 function mObcButton_onclick() {

 }

 function obcRequested(aButton) {
     var now = new Date();
     aButton.disabled = true;

     document.getElementById("obcStatus").innerHTML = "<a id='obcStatusAnchor' title='Request was sent at " + now + ".'>"
         + "Waiting for response...</a>";
     document.getElementById("obcButtonId").value = aButton.id;
     window.setTimeout("onObcRequestTimeout()", document.getElementById("obcTimeoutMillisec").value);
 }

 // response handling ********************
 function obcCallback(result, contextIsButton) {
     var columns = result.split('|');
     var readValue = "no data";
     var readDateTime = "";
     var readSource = "";
     var readStatus = "N/A";
     if (columns.length > 0) {
         readValue = columns[0];
     }
     if (columns.length > 1) {
         readDateTime = columns[1];
     }
     if (columns.length > 2) {
         readSource = columns[2];
     }
     if (columns.length > 3) {
         readStatus = columns[3];
     }

     var durationMillisec = new Date().getTime() - document.getElementById("obcRequestTimeMillisec").value;
     document.getElementById("obcStatus").innerHTML = "<a id='obcStatusAnchor' title='" + "Response in " + Math.round(durationMillisec / 1000) + " seconds (" + durationMillisec + " milliseconds).'>"
         + readStatus + "</a>";
     contextIsButton.disabled = false;
 }

 function onObcRequestTimeout() {
     if ("Waiting for response..." == document.getElementById("obcStatusAnchor").innerHTML) {
         document.getElementById("obcStatusAnchor").innerHTML = "Web Server Timed Out";
         document.getElementById(document.getElementById("obcButtonId").value).disabled = false;
     }
 }

</script>
</html>

But it is not hitting GetCallbackResult().
Can anyone help on this one?

dotnet-aspnet-webpages
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered

Hi @RamaKrishnaboyina-9136 ,
Please check your parameters of GetCallbackEventReference (). You could look for this article. You could try to run the example of the Microsoft.

Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.