locked
Induce Callback script on a PostBack RRS feed

  • Question

  • User1581882102 posted

    Hi All,

            I have a peculiar case. the scenario is i have callback functionality implemented and  a button. On Button click i modify the parameters passed to the server. please see the attached image of the script induced and when i send the alerted data, i am being being shown some text. I tried to track from where the text is being written to the browser but no luck.

    prerequisite is to have Tamper IE installed to add new parameters

    could you please provide me a solution to resolve the issue? i.e exception should be caught, instead of junk data written to the browser.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallback.aspx.cs" Inherits="ClientCallback" EnableEventValidation="true"  EnableViewStateMac="true"%>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
      <title>Client Callback Example</title>
      <script type="text/ecmascript">
        function LookUpStock()
        {
            var lb = document.getElementById("ListBox1");
            var product = lb.options[lb.selectedIndex].text;
            CallServer(product, "");
        }
        
        function ReceiveServerData(rValue)
        {   
            document.getElementById("ResultsSpan").innerHTML = rValue;
            
        }
      </script>
    </head>
    <body>
      <form id="form1" runat="server">
        <div>
          <asp:ListBox ID="ListBox1" Runat="server"></asp:ListBox>
          <br />
          <br />
          <button type="Button" onclick="LookUpStock()">Look Up Stock</button>
          
          <br />
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
          <br />
          Items in stock: <span id="ResultsSpan" runat="server"></span>
          <br />
        </div>
      </form>
    </body>
    </html>
    



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class ClientCallback : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
    {
        protected System.Collections.Specialized.ListDictionary catalog;
        protected String returnValue;
        protected void Page_Load(object sender, EventArgs e)
        {
    
            try
            {
    
                String cbReference =
                 Page.ClientScript.GetCallbackEventReference(this,
                 "arg", "ReceiveServerData", "context");
                String callbackScript;
                callbackScript = "function CallServer(arg, context)" +
                    "{ " + cbReference + ";}";
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
                    "CallServer", callbackScript, true);
    
                catalog = new System.Collections.Specialized.ListDictionary();
                catalog.Add("monitor", 12);
                catalog.Add("laptop", 10);
                catalog.Add("keyboard", 23);
                catalog.Add("mouse", 17);
    
                ListBox1.DataSource = catalog;
                ListBox1.DataTextField = "key";
                ListBox1.DataBind();
    
            }
            catch (Exception ex)
            {
    
                throw ex;
            }
        }
    
        public void RaiseCallbackEvent(String eventArgument)
        {
    
            if (catalog[eventArgument] == null)
            {
                returnValue = "-1";
            }
            else
            {
                returnValue = catalog[eventArgument].ToString();
            }
    
    
        }
        public String GetCallbackResult()
        {
            return returnValue;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
    
        }
    
    
    
    
    }

    Thursday, June 7, 2012 5:33 AM

All replies

  • User1943143334 posted

    Hi,

    Welcome to ASP.NET Forums!!!

    Is it happening in other browsers too! Try to check with Firefox/Chrome etc.,

    If it's happening with IE, then you may have to scan your computer for SPAM etc.,

    Hope it helps u...

    Thursday, June 7, 2012 7:35 AM
  • User1581882102 posted

    Thank you,

    I had tried in firefox with TamperData addon. the error is reproducable

    Thursday, June 7, 2012 9:23 AM