ESRI.ArcGIS.ADF.Web.UI.WebControls
CallbackButton Class
Members  Example  See Also 
ESRI.ArcGIS.ADF.Web.UI.WebControls Namespace : CallbackButton Class




Button that executes a server-side OnClick event during a Callback instead of a Postback.

Object Model



Syntax

Visual Basic (Declaration) 
<DefaultEventAttribute("Clicked")>
Public Class CallbackButton 
   Inherits WebControl
Visual Basic (Usage)Copy Code
Dim instance As CallbackButton
C# 
[DefaultEventAttribute("Clicked")]
public class CallbackButton : WebControl 

Example

This simple example shows how to take the text a user enters into a TextBox control and sets it as the text in a Label control. While this same operation could be done easily with client JavaScript code, the same approach could be used to do more complex server-side operations, including working with Web ADF controls such as the Map.

This sample includes the server-side code in the page, rather than in a code-behind page. If you use this sample, you will need to update the Version number in the @Register directive at the top of the page. You can also do this by removing and re-adding a reference to the ESRI.ArcGIS.ADF.Web.UI.WebControls assembly.

C#Copy Code
<%@ Page Language="C#" > <@ Register Assembly="ESRI.ArcGIS.ADF.Web.UI.WebControls, Version=9.3.0.1467, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86" 

    Namespace="ESRI.ArcGIS.ADF.Web.UI.WebControls" TagPrefix="esri" %> 

  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

  

<script runat="server"> 

  

    protected void CallbackButton1_Clicked(object sender, EventArgs args) 

    { 

        string text = CallbackButton1.CallbackArguments["txt"]; 

        CallbackButton1.CallbackResults.Add(Label1, "innercontent", text); 

    } 

</script> 

  

<html xmlns="http://www.w3.org/1999/xhtml" > 

<head runat="server"> 

    <title>Callback Button sample</title> 

</head> 

<body> 

    <form id="form1" runat="server"> 

    <div> 

        Enter some text: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 

        <br /> 

        <br /> 

        <esri:CallbackButton ID="CallbackButton1" runat="server" OnClicked="CallbackButton1_Clicked" 

            Text="Click Me!" Width="139px" CallbackArgumentsJavaScript="'txt='+document.getElementById('TextBox1').value" /> 

        <br /> 

        <br /> 

        Echo: <asp:Label ID="Label1" runat="server" Text=""></asp:Label> 

    </div> 

    </form> 

</body> 

</html> 

    
Visual BasicCopy Code
<%@ Page Language="VB" > <@ Register Assembly="ESRI.ArcGIS.ADF.Web.UI.WebControls, Version=9.3.0.1467, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86"

    Namespace="ESRI.ArcGIS.ADF.Web.UI.WebControls" TagPrefix="esri" %>



<!DOCTYPE html Public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<script runat="server">



    Protected Sub CallbackButton1_Clicked(ByVal sender As Object, ByVal args As System.EventArgs)

        Dim text As String = CallbackButton1.CallbackArguments("txt")

        CallbackButton1.CallbackResults.Add(Label1, "innercontent", text)

    End Sub

</script>



<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        Enter some text: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

        <br />

        <br />

        <esri:CallbackButton ID="CallbackButton1" runat="server" OnClicked="CallbackButton1_Clicked"

            Text="Click Me!" Width="139px" CallbackArgumentsJavaScript="'txt='+document.getElementById('TextBox1').value" />

        <br />

        <br />

        Echo: <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

    </div>

    </form>

</body>

</html>

Remarks

This control is useful when you want to trigger a callback with a normal-looking button. The CallbackButton sends its message to the server without a full postback. You can update portions of the page without refreshing the entire page this way. For more information on client callbacks, see the topic topic Working with AJAX capabilities of the Web ADF in the Developer Help. Also see the SDK Samples for examples of using the callback results collection.

Information entered in forms and other page items do not necessarily get passed back with the callback. To have these values be passed with the callback, include in CallbackArgumentsJavaScript a javascript statement that obtains the information. For example, if you need the value that the user entered into a textbox with an ID of TextBox1, you can use this value for CallbackArgumentsJavaScript:

'txt=' + document.getElementById('TextBox1').value

This javascript statement is appended to the arguments that are set for the client onclick event for the CallbackButton. The value obtained this way may be retrieved on the method that handles the server event. For example, if the the above is added to CallbackButton1, then in the click handler on the server, the item will be available in the CallbackArguments of the button.

The CallbackButton has a default event of Clicked that is called on the server. You can therefore double-click on the button in the design view of Visual Studio, and a method to handle this event will automatically be generated in the server-side code.

Inheritance Hierarchy

System.Object
   System.Web.UI.Control
      System.Web.UI.WebControls.WebControl
         ESRI.ArcGIS.ADF.Web.UI.WebControls.WebControl
            ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackButton

See Also

© 2010 All Rights Reserved.