Wrox Programmer Forums
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 20th, 2007, 08:58 PM
Registered User
Join Date: Mar 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default callback implementation

Hi All,

I was trying to implement the callback functionality to dynamically populate a second dropdown based on the value of the first 1 .....a very simple task but all my tries failed.

 I have the first dropdown populated from a table for countries and second dropdown again populated by a table for states in that country. I have them both populated during the page load based on the default values.

Now i want the state dropdown to reload with new values from the table based on the country when the country is changed through a callback rather than a postback. I tried to manipulate the msdn code but wasn;t successfull.

->i am trying to implement it on page based on a master page.
->am using vb.net in vs2005

 Also before trying this i used the sample code provided by microsoft ( http://msdn2.microsoft.com/en-us/library/ms178209(VS.80).aspx ) and tested it on a new page and it worked fine as described however when i copied the same code over to a page which was based on a master page it was giving me a javascript error saying "ReceiveServerData is undefined"(javascript function to receive the result back from server).

 Can some one please provide me with proper guidance/code to get this accomplished(even on a page based on a master page)? Am trying to implement callback for the first time.

I am also putting the case that i tried:

<%@ Page Language="VB" MasterPageFile="~/Administrator/SuperAdmin.master" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Administrator_Default2" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">

function LookUpStock()

var lb = document.getElementById("ListBox1");
var product = lb.options[lb.selectedIndex].text;

CallServer(product, "");

function ReceiveServerData(rValue)

document.getElementById("ResultsSpan").innerHTML = rValue;


<asp:ListBox ID="ListBox1" Runat="server"></asp:ListBox>

<br />

<br />

<button type="Button" onclick="LookUpStock()">Look Up Stock</button>

<br />

<br />

Items in stock: <span id="ResultsSpan" runat="server"></span>

<br />



Partial Class Administrator_Default2
Inherits System.Web.UI.Page

Implements System.Web.UI.ICallbackEventHandler
Protected catalog As ListDictionary

Protected returnValue As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim cbReference As String

cbReference = Page.ClientScript.GetCallbackEventReference(Me, _
"arg", "ReceiveServerData", "context")

Dim callbackScript As String = ""

callbackScript &= "function CallServer(arg, context) { " & _
cbReference & "} ;"

Page.ClientScript.RegisterClientScriptBlock(Me.Get Type(), _
"CallServer", callbackScript, True)

' Populate List Dictionary with invented database data

catalog = New ListDictionary()
catalog.Add("monitor", 12)

catalog.Add("laptop", 10)
catalog.Add("keyboard", 23)

catalog.Add("mouse", 17)
ListBox1.DataSource = catalog

ListBox1.DataTextField = "key"


End Sub

Public Sub RaiseCallbackEvent(ByVal eventArgument As String) _
Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackE vent

If catalog(eventArgument) Is Nothing Then

returnValue = "-1"


returnValue = catalog(eventArgument).ToString()

End If

End Sub

Public Function GetCallbackResult() _As String Implements _
System.Web.UI.ICallbackEventHandler.GetCallbackRes ult

Return returnValue

End Function
End Class

The exact same code runs fine if i implement it on a standalone page. But since this is based on a master page may be there is some other way to do it that i am not aware of.

Old August 20th, 2007, 09:46 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

Could this solution be more easily implemented with the drop down list controls in an update panel? Then you just handle the databinding of the second DDL in the same way as you would for a regular postback, but you can let the ajax framework handle the callback logic.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remoting Callback problem downboat BOOK: Professional C#, 2nd and 3rd Editions 2 June 8th, 2011 02:13 AM
charpter 4 callback feature mlcy BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 4 July 10th, 2008 05:16 PM
Callback in 3 DropDownLists Paula222 ASP.NET 2.0 Professional 3 December 13th, 2006 08:53 AM
Worldpay Callback Script Countach1976 PHP Databases 3 January 1st, 2005 10:36 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.