ASP.NET
  Home arrow ASP.NET arrow Adding Comments and Search to an ASP.NET A...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBMฎ developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Adding Comments and Search to an ASP.NET AJAX Server-Centric Based Online Shopping Website
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2008-01-02

    Table of Contents:
  • Adding Comments and Search to an ASP.NET AJAX Server-Centric Based Online Shopping Website
  • Leaving Words
  • Advanced Search
  • Advanced Search continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Adding Comments and Search to an ASP.NET AJAX Server-Centric Based Online Shopping Website


    (Page 1 of 4 )

    In real scenarios, an online shopping city must support the users to make free comments on the goods as well as leave suggestions to help the city owners to further improve their services. In this example in the sixth part of an eleven-part series, we have simulated these functionalities. We also set up the search functions.
    A downloadable .rar file is available for this article.

    Making comments on the Products

    This function is performed through the "comment.aspx" page. Let’s take a quick look at the related design-time snapshot, as illustrated in the following Figure 19.


    Figure 19—the design-time snapshot for making comments

    Apparently, this is a simple yet representative design concerning the ASP.NET AJAX server-centric pages. At the top lies the ScriptManager controlto schedule the relations between ASP.NET and the MS AJAX framework itself. The middle part is a GridView circled by the UpdatePanel controlto gain the partial update effect as the GridView control changes its contents. The lower part is two TextBox controls for the user to populate with his comments. At the bottom are two buttons: "Submit my comment" for submitting the comment and "Close" for closing the current browser window.

    There are two points here worth pointing out. First, we purposely omit the utilization of ASP.NET AJAX server control namedUpdateProgessand the ASP.NET AJAX Control Toolkit Extender control namedUpdatePanelAnimation,both here and in the rest of this sample, partially to save  writing time. Second, despite the scope of the UpdatePanel controlwe can still not securely use the sentence we mentioned earlier: ‘Response.Write(“<script>…</script>”);’.

    Now, let’s omit the analysis of binding data to the GridView "CommentView," but leave room for submitting the comment. Clicking the "Submit my comment" button will trigger the SureBtn_Click event handler. The following shows the related code:

    protected void SureBtn_Click(object sender,EventArgs e){

    if(Session["UserID"] == null) {

    ScriptManager.RegisterStartupScript(up1, typeof(UpdatePanel),
    "ScriptName1", "alert('Not logged in. Please login first!')", true);

    return;

    }

    Comment comment = new Comment();

    comment.AddComment(Desn.Text,Body.Text,nProductID,Int32.Parse(Session
    ["UserID"].ToString()));

    ///rebind data

    BindCommentData(nProductID);

    }

    protected void ReturnBtn_Click(object sender,EventArgs e){

    Response.Write("<script>window.close();</script>");

    }

    Note here in the SureBtn_Click function, we still use the static method named RegisterStartupScriptof ScriptManagerto report to the user an error message instead of using the ‘Response.Write(“<script>…</script>”);’sentence, or else you will surely meet the error shown in the following Figure 20.


    Figure 20—the typical error message when ‘Response.Write(…)’ conflicts with UpdatePanel

    In contrast, in the event handler for the "ReturnBtn" button, we have used ‘Response.Write("<script>window.close();</script>");’. To our astonishment, there is nothing wrong and the page closes in the normal way. Why? According to the result of my simple study, if you use ‘Response.Write()’to directly write JavaScript functions such as alert()to the page during the course of a asynchronous postback, these functions often do not run as expected and even result in some error. Therefore, in the first function above if we use ‘Response.Write()’ instead of ‘ScriptManager.RegisterStartupScript(…)’, then the asynchronous postback action triggered by the subsequent sentences will of course lead to the error in Figure 20. However, in the second function, there is only one simple sentence ‘Response.Write()’, this of course will not result in an error occurring.

    More ASP.NET Articles
    More By Xianzhong Zhu


     

    ASP.NET ARTICLES

    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...
    - Building an In-Text Advertising System Under...
    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT