初學者,照著書本key....
執行畫面:
程式:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication5
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
Response.Write("網頁<b> 第一次值行 </b>...Page Load 事件...<br />");
}
else
{
int q = Convert.ToInt32(TextBox1.Text) + 1;
TextBox1.Text = q.ToString();
Response.Write("網頁重新 PostBack(回傳)....Page Load 事件...<br />");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("按下[按鈕]....button 的 click 事件...<br />");
}
}
}
成功...!!
網頁即時通:
namespace WebApplication_Communication
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string A = TextBox2.Text + ":" + TextBox4.Text; //發言者:發言
TextBox1.Text += A + "\r\n"; //寫入看板
Application[TextBox3.Text] = A; //發給收訊者
TextBox4.Text = ""; //清除發言框
}
protected void Timer1_Tick(object sender, EventArgs e)
{
if(Application[TextBox2.Text]!=null)
{
TextBox1.Text += Application[TextBox2.Text] + "\r\n";//寫入看板
Application[TextBox2.Text] = null; //刪除訊息
}
}
}
}
執行結果: