Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Events Between Web Forms

, 6 Jul 2007 CPOL
Raise Events Between Web Forms Using CallBacks or Ajax
using System;
using System.Data;
using System.IO;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Script.Services;


namespace CallBacks
{
/// <summary>
/// Summary description for WSUsers
/// </summary>
[ScriptService]
public partial class WSUsers : System.Web.Services.WebService
{
    [WebMethod (Description = "Add a New User")]
    [ScriptMethod]
    public string AddUser(string Name, int Age)
    {
        //The datasource
        DataSet DS = new DataSet();
        //Check the file exists
        FileInfo file = new FileInfo(Server.MapPath(System.Web.HttpRuntime .AppDomainAppVirtualPath) + "/Data.xml");
        if (!file.Exists)
        {
            DS.Tables.Add("Users");
            DS.Tables["Users"].Columns.Add("User Name", typeof(string));
            DS.Tables["Users"].Columns.Add("Age", typeof(int));
        }
        else
        {
            DS.ReadXml(file.FullName);
        }

        //Add the User
        DataRow User = DS.Tables["Users"].NewRow();
        User[0] = Name;
        User[1] = Age;
        DS.Tables["Users"].Rows.Add(User);
        //Write the DS to the file
        DS.WriteXml(file.FullName, XmlWriteMode.WriteSchema);

        return "Added User Name:" + Name + " Age:" + Age.ToString() + "    Added At:" + DateTime.Now.ToShortDateString();
    }
 }
}


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)

Share

About the Author

Pramirez
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#.

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 6 Jul 2007
Article Copyright 2007 by Pramirez
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid