当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 改写即时消息的发送 包含同时给多人发送信息

ASP.NET
asp.net Linq TO Sql 分页方法
asp.net 用XML生成放便扩展的自定义树
asp.ent下合并两个结构相同的DataTable
asp.net 遍历repeater中的控件的几种方式
asp.net 处理原文件中过长的viewstate代码
asp.net下遍历页面中所有的指定控件的代码
获取创建Membership的数据库创建脚本
asp.net AJAX注册类
asp.net 处理F5刷新页面重复提交页面的一个思路
ASP.NET 缓存分析和实践浅析提高运行效率
asp.net 读取并显示excel数据的实现代码
ASP.NET中常用的用来输出JS脚本的类
ASP.NET中内嵌页面代码的一个问题
asp.net(C#)操作excel(上路篇)
一个基于Asp.Net MVC的权限方案
ASP.NET实例教程:51job网站地区选择功能
ASP.NET教程:友好的Html和JS适合SEO
ASP.NET教程:使用.ashx文件去除重复内容
ASP.NET做SEO:制作架构清晰和更新及时的网站地图
ASP.NET优化:Sql注入和Html注入的黑帽SEO

ASP.NET 中的 改写即时消息的发送 包含同时给多人发送信息


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-23   浏览: 77 ::
收藏到网摘: n/a

以前的的发送消息按钮事件改写如下:

 


'/////////////////////参数构造
tostu_id=tostu_id&CheckBoxList1.Items(i).Text&"@"
Else
Label2.Visible=True
Label2.Text="一次最多能给五个用户发送信息!"
Return
'Response.Write("<scriptlanguage=JavaScript>window.open('info.aspx?tostu_id='&CheckBoxList1.Items(i).Text,'','height=330,width=560,status=no,location=no,toolbar=no,directories=no,menubar=no')</script>")
EndIf
EndIf
Nexti
Response.Redirect("info.aspx?tostu_id="&tostu_id)
EndSub

这里发送信息的页面由于修改的比较多,所以把全部代码全都抓来了,呵呵:)

codebebind部分:


ImportsSystem.Data
ImportsSystem.Data.SqlClient
PublicClassinfo
InheritsSystem.Web.UI.Page
ProtectedWithEventsLabel1AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel2AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsTextBox2AsSystem.Web.UI.WebControls.TextBox
ProtectedWithEventsButton1AsSystem.Web.UI.WebControls.Button
ProtectedWithEventsButton2AsSystem.Web.UI.WebControls.Button
ProtectedWithEventsLabel3AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel4AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel5AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel6AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsTextBox3AsSystem.Web.UI.WebControls.TextBox
ProtectedWithEventsImage3AsSystem.Web.UI.WebControls.Image
ProtectedWithEventsLabel8AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel7AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel9AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel10AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsButton3AsSystem.Web.UI.WebControls.Button
ProtectedWithEventsLabel11AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsTextBox1AsSystem.Web.UI.WebControls.TextBox

#Region"WebFormDesignerGeneratedCode"

'ThiscallisrequiredbytheWebFormDesigner.
<System.Diagnostics.DebuggerStepThrough()>PrivateSubInitializeComponent()

EndSub

PrivateSubPage_Init(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Init
'CODEGEN:ThismethodcallisrequiredbytheWebFormDesigner
'Donotmodifyitusingthecodeeditor.
InitializeComponent()
EndSub

#EndRegion
DimconnAsSqlConnection=NewSqlConnection("server=lixinri;uid=sa;pwd=;database=99re1")
PublicSubPage_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load
IfNotIsPostBackThen
Dimtostu_idAsString=Request.QueryString("tostu_id")
Dimsplitname()AsString
'///////////这里用了Split函数将传过来的参数取出
splitname=Split(tostu_id,"@")
Iftostu_id=""Then
'//////////////////当回复留言时
DimsqlAsString="selecta.*,b.nickfrominfoa,pwdbwherea.fromstu_id=b.stu_idanda.tostu_id='"&Session("stu_id")&"'anda.term=1"
DimcommAsSqlCommand=NewSqlCommand(sql,conn)
DimdrAsSqlDataReader
conn.Open()
dr=comm.ExecuteReader
Whiledr.Read
Label3.Text=dr.Item("nick")
Label4.Text=dr.Item("tim")
Label5.Text=""&dr.Item("content")
TextBox1.Text=dr.Item("nick")
TextBox3.Text=dr.Item("fromstu_id")
TextBox1.Enabled=False
Label8.Visible=False
Label11.Visible=False
EndWhile
dr.Close()
comm.Cancel()
'//////////////////////更新留言使留言属性为已阅读过
Dimsql_1AsString="updateinfosetterm=0wheretostu_id='"&Session("stu_id")&"'andterm=1andtim='"&Label4.Text&"'"
comm=NewSqlCommand(sql_1,conn)
comm.ExecuteNonQuery()
Else
'////////////////////当发送留言时
'/////////////////读取参数
DimiAsInteger
Fori=0ToUBound(splitname)-1
DimmysqlAsString="selectnickfrompwdwherestu_id='"&splitname(i)&"'"
DimcommAsSqlCommand=NewSqlCommand(mysql,conn)
DimdrAsSqlDataReader
Ifi=0Then
conn.Open()
dr=comm.ExecuteReader
Ifdr.ReadThen
TextBox1.Text=Trim(dr.item("nick"))&";"
EndIf
control()
dr.close()
Else
dr=comm.ExecuteReader
Ifdr.ReadThen
TextBox1.Text=TextBox1.Text&Trim(dr.item("nick"))&";"
EndIf
control()
dr.close()
EndIf
Nexti
EndIf
EndIf
EndSub
'/////////////////control事件,没有什么实际意义,使代码简单罢了。
Subcontrol()
TextBox1.Enabled=False:Label3.Text="":Label4.Text="":Label5.Visible=False
Label8.Visible=True:Label6.Visible=False:Label7.Visible=False:Label9.Visible=False
Button3.Visible=False:Label11.Visible=True
Label11.Text="<ahref=board.aspx><<<返回学友录</a>"
EndSub

'/////////////////书写提交消息事件
PublicSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
Dimtostu_idAsString=Request.QueryString("tostu_id")
Dimsplitname()AsString
splitname=Split(tostu_id,"@")
Iftostu_id=""Then
'/////////////////////////当回复留言时
IfTextBox2.Text=""OrTextBox2.Text=""Then
Label10.Visible=True
Label10.Text="消息不能为空!"
Return
Else
Label10.Visible=False
conn.Open()
DimsqlAsString="insertintoinfo(fromstu_id,tostu_id,content,term,tim)values(@fromstu_id,@tostu_id,@content,@term,@tim)"
DimcommAsSqlCommand=NewSqlCommand(sql,conn)
comm.Parameters.Add(NewSqlParameter("@fromstu_id",SqlDbType.Int,4))
comm.Parameters("@fromstu_id").Value=Session("stu_id")

comm.Parameters.Add(NewSqlParameter("@tostu_id",SqlDbType.Int,4))
comm.Parameters("@tostu_id").Value=TextBox3.Text

comm.Parameters.Add(NewSqlParameter("@content",SqlDbType.VarChar,200))
comm.Parameters("@content").Value=TextBox2.Text

comm.Parameters.Add(NewSqlParameter("@term",SqlDbType.Int,4))
comm.Parameters("@term").Value="1"

comm.Parameters.Add(NewSqlParameter("@tim",SqlDbType.Char,20))
comm.Parameters("@tim").Value=Date.Now
comm.ExecuteNonQuery()
'TextBox2.Text=""
EndIf
Else
'/////////////////////////当发送留言时
IfTextBox2.Text=""OrTextBox2.Text=""Then
Label10.Visible=True
Label10.Text="消息不能为空!"
Return
Else
'////////////////插入i条数据
DimiAsInteger
Fori=0ToUBound(splitname)-1
Label10.Visible=False
Ifi=0Then
conn.Open()
Else
EndIf
DimsqlAsString="insertintoinfo(fromstu_id,tostu_id,content,term,tim)values(@fromstu_id,@tostu_id,@content,@term,@tim)"
DimcommAsSqlCommand=NewSqlCommand(sql,conn)
comm.Parameters.Add(NewSqlParameter("@fromstu_id",SqlDbType.Int,4))
comm.Parameters("@fromstu_id").Value=Session("stu_id")

comm.Parameters.Add(NewSqlParameter("@tostu_id",SqlDbType.Int,4))
comm.Parameters("@tostu_id").Value=splitname(i)

comm.Parameters.Add(NewSqlParameter("@content",SqlDbType.VarChar,200))
comm.Parameters("@content").Value=TextBox2.Text

comm.Parameters.Add(NewSqlParameter("@term",SqlDbType.Int,4))
comm.Parameters("@term").Value="1"

comm.Parameters.Add(NewSqlParameter("@tim",SqlDbType.Char,20))
comm.Parameters("@tim").Value=Date.Now
comm.ExecuteNonQuery()
'TextBox2.Text=""
Nexti
EndIf
EndIf
Response.Write("<scriptlanguage=javascript>alert('发送成功!')</script>")
EndSub

'////////////////////返回继续发送
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
Response.Redirect("boaman.aspx")
EndSub

PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
Response.Write("<scriptlanguage=javascript>window.close()</script>")
EndSub
EndClass

感谢laodeng了:)