惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - Aowind

Freeswitch 安装爬坑记录1 兜兜转转,最后还是又回来研发了。 我的博客即将入驻“云栖社区”,诚邀技术同仁一同入驻。 好久没有写随笔了,记录个旋转算法。 我的G1,1.6固件,用起来越来越感觉不错了 JSON定义AS项目界面 - Aowind - 博客园 [转]将数据库表存入内存中,随时调用 [转]asp.net中对DataTable数据进行排序、检索、合并、分页、统计 - Aowind - 博客园 AjaxPro快速入门 最近的工作 光阴真的是贱(似箭),一不小心就又过一年了 简单的无框架Ajax应用 一个事件应用的例子 [转载]P2P之UDP穿透NAT的原理与实现 [转载].Net和Flash如何进行数据交互 一个实例来简单的说明接口 有关Asp里Split函数使用多个分割符的方法 自己写的一个asp.net的生成曲线图的过程 用于模拟短信群发情况的随机数产生
利用Ajax技术写一个迷你留言板WEB控件
Aowind · 2006-11-21 · via 博客园 - Aowind

初学Ajax不久,自己写个小东西,以作学习日记
留言板图片如下:
{56B69F79-4349-4E3C-B28A-FC8885FE3C34}.JPG
样例地址:http://www.8dao.net/miniguest/

首先,这里用的是Access数据库,便于移动。
数据库很简单,表Guest,字段有ID,Name,Content

要实现Ajax,利用asp.net ajax 1.0 bate是很方便的,在http://ajax.asp.net可以下载到。
安装好后打开VS2005,新建一个ASP.net AJAX Enabled Web Site项目
在里面添加一个WEB用户控件 MiniGB.ascx,控件代码如下:

<%@ Control Language="C#" ClassName="MiniGB" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>

<script runat="server">
   
 
    private OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source="+System.Web.HttpContext.Current.Server.MapPath("guest.mdb"));
    private string dname = "游客";
    public string Dname
    {
        get
        {
            return dname;
        }
        set
        {
            dname = value;
        }
    }
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.Trim() != "")
        {
            OleDbCommand comm = new OleDbCommand("insert into guest(name,content)values('"+dname+"','" + TextBox1.Text.Trim() + "')", conn);
            comm.ExecuteNonQuery();
            listupdate();
            TextBox1.Text = "";
        }
    }
    private void listupdate()
    {
        OleDbDataAdapter da = new OleDbDataAdapter("select top 5 * from guest order by id desc", conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataList1.DataSource = ds;
        DataList1.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        conn.Open();
        listupdate();
    }
</script>
<style>
.Gtitle
{
width:200px;
background-color:#464646;
color:#FFFFFF;
font-size:14px;
height:20px;
padding: 3px 0 0 10px;
font-weight:bold;
border-style:solid;
border-top-width:1px;
border-bottom-width:0px;
border-left-width:1px;
border-right-width:1px;
border-color:#BBBBBB;
}
.Gbody
{
width:200px;
border-style:solid;
border-top-width:0px;
border-bottom-width:0px;
border-left-width:1px;
border-right-width:1px;
border-color:#BBBBBB;
padding:3px 5px 3px 5px;
}
.Gend
{
width:200px;
border-style:solid;
border-top-width:0px;
border-bottom-width:1px;
border-left-width:1px;
border-right-width:1px;
border-color:#BBBBBB;
padding:3px 5px 3px 5px;

}
.Gname
{
width:190px;
 font-size:12px;
 color:blue;

}
.Gcontent
{
width:190px;
word-break:break-all;
color:#444444;
font-size:12px;
padding: 3px 0 3px 0;
border-style:dotted;
border-top-width:0px;
border-bottom-width:1px;
border-left-width:0px;
border-right-width:0px;
border-color:#BBBBBB;
}
</style>

<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div class="Gtitle"><asp:Label ID="Label1" runat="server" Text="留言板"></asp:Label></div>
        <div class="Gbody"><asp:DataList ID="DataList1" runat="server" >
        <ItemTemplate>
        <div class="Gname"><%# DataBinder.Eval(Container.DataItem, "name") %> 说:</div><div class="Gcontent"><%# DataBinder.Eval(Container.DataItem, "content") %></div>
        </ItemTemplate>
        </asp:DataList></div>
        <div class="Gend"><asp:TextBox ID="TextBox1" runat="server" Width="150px" />
        <asp:Button ID="Button1" runat="server" Text="留言" OnClick="Button1_Click" /></div>
    </ContentTemplate>
</asp:UpdatePanel>

这样就可以完成这个控件了,然后就是在页面上调用这个控件了,调用这个控件的页面必须有一个ScriptManager控件才能使用。

此控件修改一下可以做为文章评论控件用,加上个:更多。。。,按文章ID显示评论就可以用了。

初学Ajax,做一应用,做为学习日志。还望多指教。