ASP.NET
  Home arrow ASP.NET arrow Page 4 - Completing an In-Text Advertising System u...
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

Completing an In-Text Advertising System under an ASP.NET 3.5 Environment
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2009-01-28

    Table of Contents:
  • Completing an In-Text Advertising System under an ASP.NET 3.5 Environment
  • The Verification Code
  • The Member Center: the siteUser.aspx page
  • Manage the Ad Keywords
  • Manage the Ad Contents

  • 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


    Completing an In-Text Advertising System under an ASP.NET 3.5 Environment - Manage the Ad Keywords


    (Page 4 of 5 )

    There are two pages associated with the system administrator: the Admin1.aspx page and Admin2.aspx. The Admin1.aspx page seeks to manipulate the ad keywords, while the Admin2.aspx page takes care of managing the related ad contents. Figure 3 gives one of the running time snapshots for the Admin1.aspx page.


    Figure 3—Admin2.aspx: managing the ad contents

    As you’ve seen, the "Admin1.aspx" page uses a GridView control to manage the ad keywords. In this page, you can browse, remove, and add any of your favorite ad keywords.

    The following responds to the HTML code of the "Admin1.aspx" page:

    <body>

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

    <div><a href ="admin2.aspx">Go to manage the AD contents</a><br /><br />

    <asp:GridView id="GridView1" runat="server" AutoGenerateColumns="False" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCommand="GridView1_RowCommand" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None">

    <Columns>

    <asp:BoundField DataField="id" HeaderText="Code" />

    <asp:BoundField DataField="name" HeaderText="Keyword" />

    <asp:BoundField DataField="notes" HeaderText="Note" />

    <asp:TemplateField HeaderText="delete">

    <ItemTemplate>

    <asp:LinkButton ID="LinkButton1" CommandName ="del" runat="server" CommandArgument='<%# Bind("id") %>'>Delete</asp:LinkButton>

    </ItemTemplate>

    </asp:TemplateField>

    </Columns>

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <EditRowStyle BackColor="#999999" />

    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

    </asp:GridView>

    <br />

    Keyword:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

    Note:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

    <br />

    <br />

    <asp:Button ID="Button1" runat="server" Text="Add" OnClick="Button1_Click" />

    </div>

    </form>

    </body>

    What about the code behind it? Below is the crucial part of the code:

    protected void Page_Load(object sender, EventArgs e)

    {

    //not logged, then force to login first

    if (Session["admin"]==null||Session["admin"].ToString() != "true") Response.Redirect("login.aspx");

    if (!IsPostBack)

    {

    myDataBind();//data binding

    }

    }

    //paging

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

    GridView1.PageIndex = e.NewPageIndex;

    myDataBind();

    }

    //delete

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

    {

    if (e.CommandName == "del")

    {

    string id = e.CommandArgument.ToString();

    try

    {

    Sql s = new Sql();

    s.ExecuteSql("delete from keyarray where id=" + id);//delete

    myDataBind();

    }

    catch

    { }

    }

    }

    //datasource binding

    private void myDataBind()

    {

    Sql s = new Sql();

    DataSet ds = s.getMyDataSet("select * from keyarray order by id desc");

    GridView1.DataSource = ds;

    GridView1.DataBind();

    }

    //add the ad keyword

    protected void Button1_Click(object sender, EventArgs e)

    {

    int result;

    Sql s = new Sql();

    //add the ad keyword

    result = s.ExecuteSql("insert into keyarray([name],notes) values('"+TextBox1.Text+"','"+ TextBox2.Text+"')");

    string msg = "alert('Operation failed!')";

    if (result == 1)//if peration succeeded,then prompt

    {

    TextBox2.Text = TextBox1.Text = "";

    msg = "alert('Operation succeeded!')";

    myDataBind();

    }

    //the client side prompt

    ClientScript.RegisterStartupScript(this.GetType(), "asdf", msg, true);

    }

    As you’ve seen, the system first judges whether the current user is the valid administrator with the help of ASP.NET Sesson, and if not, it redirects him to the "login.aspx" page. Next, it makes the necessary preparations for the GridView control, i.e. binds data and adds related operating buttons. Finally, when the user clicks the "Add" button, a typical database INSERT operation is triggered to append the newly-populated ad keyword-related data to the backend database. That’s it.

    More ASP.NET Articles
    More By Xianzhong Zhu


       · This is a very good article. Is there going to be another part to this series?
     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek