Build an AJAX Based ASP.NET Web Tag Application - Part 2
page 8 of 12
by Xianzhong Zhu
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 45459/ 60

Modifying a Web Tag Category

This rough idea of the modifying operation here is quite similar to that in adding and deleting a tag category. First, the server side page is RenameSection.aspx, whose behind code is listed below.

Listing 17

protected void Page_Load(object sender, EventArgs e)
{
      if ((Request.Params["id"] != null) &&
              (Request.Params["name"] != null))
      {
            // the tag category id to be modified
            int iSectionId = Convert.ToInt32(Request.Params["id"]);
 
            // the new web tag name
            string strSectionName = Request.Params["name"];
 
            // set up the database access object
            Database db = DatabaseFactory.CreateDatabase
             ("DatabaseConnectionString");
 
            // define the SP RenameSection related object
            string sqlCommand = "RenameSection";
            DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
 
            // provide the input parameters for the SP
            db.AddInParameter(dbCommand, "id", DbType.Int32, iSectionId);
            db.AddInParameter(dbCommand, "name", DbType.String, strSectionName);
 
            // execute the stored procedure
            db.ExecuteNonQuery(dbCommand);
      }
}

Here, the stored procedure RenameSection is invoked. And also, we have to pass in the two related arguments id and name which represent the id and the name property of the modifying tag category respectively.

In contrast to the above, on the client side, we still leverage "Ajax.Request" class to send out requests to page RenameSection.aspx, whose script code is as follows.

Listing 18

function RenameSection(id) {
      var sectionName = window.prompt("Please enter a new tag category name");
      if (sectionName) {
            var paras = "id=" + id + "&name=" + escape(sectionName);
            new Ajax.Request("RenameSection.aspx", {
                  mothed: "GET",
                  parameters: paras,
                  onComplete: function(xmlhttp) 
 {
                        new Ajax.Request("ListSection.aspx", 
                        {onComplete: InitSection});
                  }
            });
      }
}

Here, we first use the JavaScript window.prompt dialog to let the user enter a new tag category name. Then, construct the parameter passed to page RenameSection.aspx. And finally, asynchronously call page RenameSection.aspx to accomplish the task of modifying the category name behind the scene.


View Entire Article

User Comments

Title: Thanks   
Name: Cong Doan
Date: 2009-04-13 11:17:25 AM
Comment:
Thanks for your Article! It's wonderful!






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-24 10:19:10 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search