Click here to Skip to main content
15,885,309 members
Articles / Web Development / IIS

Events Between Web Forms

Rate me:
Please Sign up or sign in to vote.
4.59/5 (12 votes)
6 Jul 2007CPOL4 min read 43.2K   947   48  
Raise Events Between Web Forms Using CallBacks or Ajax
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxCallBack.aspx.cs" Inherits="AjaxCallBack" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<!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 runat="server">
    <title>Add a user using Web Services and Ajax</title>
    <script type="text/javascript">
    
        // Callback function 
        function SucceededCallback(CallBackResult, eventArgs)
        {
                //Inform the user
                document.getElementById("ResultsSpan").innerHTML = CallBackResult;
                //UserAdded
                window.opener.UserAddedEvent(CallBackResult);

        }
        
        //Adds the user
        function AddUser()
        {
            CallBacks.WSUsers.AddUser(document.getElementById("txtName").value,document.getElementById("txtAge").value,SucceededCallback);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

        User Name
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
        Age &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
        <asp:TextBox ID="txtAge" runat="server"></asp:TextBox><br />
      <br />
      <button type="Button" onclick="AddUser();">Add</button>
      <br />
      <br />
      <span id="ResultsSpan" runat="server"></span>
    </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Mexico Mexico
I am Pedro Ramirez from mexico, work for www.sciodev.com, the company is located in Mexico, we do outsourcing and nearshore development, we are focused on SaaS nearshore development, I started with VB.Net, but now I am ambidextrous using VB.Net or C#.

Comments and Discussions