人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

無刷新的聊天室的制作兼談組件制作與ClientSide Script(二)

無刷新的聊天室的制作兼談組件制作與ClientSide Script(二)

更新時間:2022-06-07 文章作者:未知 信息來源:網絡 閱讀次數:

好了,至此,我們的webservice就完成了,大家可能不滿了,還是沒實現無刷新嘛,別急,這是客戶端的事。下面我們就來做這項工作。
一般來說我們完全可以做一個html頁面,而不用server page,但為了順便說明怎樣做組件,我決定作一個server control,先來看一下代碼
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;

namespace Michael.Web.UI.Controls
{
/// <summary>
/// Summary description for chat.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:chat runat=server></{0}:chat>")]
public class chat : System.Web.UI.WebControls.Table
{
private string doc;
private string text;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}

/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
// The script block is written to the client
output.Write(doc);

base.Render(output);
}

private string Serviceurl = "http://localhost/chat/ChatWebService.asmx?WSDL";
[Bindable(true),
Category("WebServiceProperty"),
DefaultValue("http://localhost/chat/ChatWebService.asmx?WSDL")]
public string ServiceURL
{
get
{
return Serviceurl;
}
set
{
Serviceurl = value;
}
}
private string Behaviorurl = "http://localhost/chat/webservice.htc";
[Bindable(true),
Category("WebServiceProperty"),
DefaultValue("")]
public string BehaviorURL
{
get
{
return Behaviorurl;
}
set
{
Behaviorurl = value;
}
}

private string tablecssclass;
[Bindable(true),
Category("LayoutProperty"),
DefaultValue("")]
public string TableCssClass
{
get
{
return tablecssclass;
}
set
{
tablecssclass = value;
}
}

private string titlecssclass;
[Bindable(true),
Category("LayoutProperty"),
DefaultValue("")]
public string TitleCssClass
{
get
{
return titlecssclass;
}
set
{
titlecssclass = value;
}
}

private string onlinecssclass;
[Bindable(true),
Category("LayoutProperty"),
DefaultValue("")]
public string OnlineCssClass
{
get
{
return onlinecssclass;
}
set
{
onlinecssclass = value;
}
}

private string msgcssclass;
[Bindable(true),
Category("LayoutProperty"),
DefaultValue("")]
public string MSGCssClass
{
get
{
return msgcssclass;
}
set
{
msgcssclass = value;
}
}

private string selusercssclass;
[Bindable(true),
Category("LayoutProperty"),
DefaultValue("")]
public string SelUserCssClass
{
get
{
return selusercssclass;
}
set
{
selusercssclass = value;
}
}
protected override void OnInit(EventArgs e)
{
this.ID = "service";

this.Style["Behavior"] = "url('" + Behaviorurl + "')";

this.Style["Table-Layout"] = "Fixed";

if( this.Attributes["class"] == null) this.Attributes["class"] = tablecssclass;

this.Attributes["onresult"] = UniqueID + "_onmyresult();";

TableRow tr;
// And also create 7 Table Cell elements one by one
TableCell cell = new TableCell();

cell.Attributes["class"] = titlecssclass;
cell.Attributes["Align"] = "Left";

// Set the caption of the control
cell.Text = "Portal 聊天室";
// Instantiate a Table Roa and attach the First Cell to it
tr = new TableRow();
tr.Cells.Add(cell);
// Add the Table Row to our Control
this.Rows.Add(tr);

// Row No 2 starts here

cell = new TableCell();

cell.Attributes["class"] = onlinecssclass;
cell.Text = "在線人員";
tr = new TableRow();
tr.Cells.Add(cell);
this.Rows.Add(tr);

// Row No 3 Starts here

cell = new TableCell();
cell.Style["Height"] = "25%";
// We create a DIV element using HtmlGenericControl object
// We can also do this using the Panel object
HtmlGenericControl d = new HtmlGenericControl("Div");
d.ID = UniqueID + "_ChatMsgs";
d.Style["Height"] = "100%";
d.Style["Width"] = "100%";
d.Style["Overflow"] = "Auto";
d.Style["Padding-Left"] = "15%";
d.ID = UniqueID + "_ChatList";
// Adding the DIV element to the Table Cell
cell.Controls.Add(d);
tr = new TableRow();
tr.Cells.Add(cell);
this.Rows.Add(tr);

// Row No 4 Starts here

cell = new TableCell();

cell.Attributes["class"] = msgcssclass;
cell.Text = "消息:";
tr = new TableRow();
tr.Cells.Add(cell);
this.Rows.Add(tr);

// Row No 5 starts here

cell = new TableCell();
cell.Style["Height"] = "35%";
d = new HtmlGenericControl("Div");
d.ID = UniqueID + "_ChatMsgs";
d.Style["Height"] = "100%";
d.Style["Width"] = "100%";
d.Style["Overflow"] = "Auto";
cell.Controls.Add(d);
tr = new TableRow();
tr.Cells.Add(cell);
this.Rows.Add(tr);

// Row No 6 Starts here

cell = new TableCell();

cell.Attributes["class"] = selusercssclass;
cell.ID = UniqueID + "_Prompt";
cell.Text = "選擇一個用戶:";
tr = new TableRow();
tr.Cells.Add(cell);
this.Rows.Add(tr);

// Row No 7 starts here

cell = new TableCell();
cell.Text = "<INPUT Type=\"Text\" id= '" + UniqueID + "_UserInput'> \r\n";
cell.Text += "<BR>\r\n";
cell.Text += "<Button id = '" + UniqueID + "_bnSendMsg' onclick = \"return SendMsg();\" class = " + UniqueID + "_TitleLabel style = \"display:none\"> 發送 </Button>\r\n";
cell.Text += "<Button id = '" + UniqueID + "_bnSelectName' onclick = \"return " + UniqueID + "_SelectName();\" class = " + UniqueID + "_TitleLabel style = \"display:block\"> 登陸 </Button> \r\n";
cell.Style["Color"] = "Black";
cell.Style["Background-Color"] = "Gainsboro";
tr = new TableRow();
tr.Cells.Add(cell);
this.Rows.Add(tr);

// First script Block is written into 'doc' variable

doc = "\r\n<SCRIPT FOR = 'window' EVENT = 'onload()'>";
doc += "//alert(\"done\"); \r\n";
doc += "service.use(\"";
doc += Serviceurl + "\",\"ChatWebService\"); \r\n";
doc += "" + UniqueID + "_UserInput.focus();\r\n";
doc += "</SCRIPT> \r\n";
 
// Then the second script block follows
 
doc += "<script language=\"JavaScript\">\r\n";
doc += "var " + UniqueID + "_iCallID1, " + UniqueID + "_iCallID2, " + UniqueID + "_iCallID3; \r\n";
doc += "var " + UniqueID + "_NickName; \r\n";
doc += "var " + UniqueID + "_MsgXML = new ActiveXObject(\"MSXML.DOMDocument\");\r\n";
doc += "function " + UniqueID + "_SelectName() \r\n";
doc += "{ \r\n";
doc += "if (" + UniqueID + "_UserInput.value == \"\") return false;\r\n";
doc += "" + UniqueID + "_NickName = " + UniqueID + "_UserInput.value; \r\n";
doc += "" + UniqueID + "_bnSelectName.disabled = 'true'; \r\n";
doc += "" + UniqueID + "_UserInput.disabled = 'true';\r\n";
doc += "" + UniqueID + "_iCallID1 = service.ChatWebService.call(\"Login\"," + UniqueID + "_NickName); \r\n";
doc += "} \r\n";
doc += "function " + UniqueID + "_onmyresult() \r\n";
doc += "{ \r\n";
doc += "if((event.result.error)&&(" + UniqueID + "_iCallID1==event.result.id)) \r\n";
doc += "{ \r\n";
doc += "var xfaultcode = event.result.errorDetail.code; \r\n";
doc += "var xfaultstring = event.result.errorDetail.string; \r\n";
doc += "var xfaultsoap = event.result.errorDetail.raw;\r\n";
doc += "\r\n";
doc += "// Add code to output error information here\r\n";
doc += "alert(xfaultstring);\r\n";
doc += "" + UniqueID + "_bnSelectName.disabled = false;\r\n";
doc += "" + UniqueID + "_UserInput.disabled = false; \r\n";
doc += "" + UniqueID + "_UserInput.focus();\r\n";
doc += "\r\n";
doc += "} \r\n";
doc += "else if((!event.result.error)&&(" + UniqueID + "_iCallID1==event.result.id)) \r\n";
doc += "{ \r\n";
doc += "" + UniqueID + "_ChatList.innerText= event.result.value; \r\n";
doc += "" + UniqueID + "_ChatList.scrollTop =2000; \r\n";
doc += "" + UniqueID + "_bnSelectName.style.display = 'none';\r\n";
doc += "" + UniqueID + "_bnSendMsg.style.display = 'block';\r\n";
doc += "" + UniqueID + "_UserInput.value = \"\"; \r\n";
doc += "" + UniqueID + "_UserInput.disabled = false; \r\n";
doc += "" + UniqueID + "_UserInput.focus();\r\n";
doc += "" + UniqueID + "_Prompt.innerText = " + UniqueID + "_NickName + \" 說:\"; \r\n";
doc += "window.setTimeout('" + UniqueID + "_iCallID2 = service.ChatWebService.call(\"GetMsgs\"," + UniqueID + "_NickName);',3000); \r\n";
doc += "} \r\n";
doc += "else if((event.result.error)&&(" + UniqueID + "_iCallID2==event.result.id))\r\n";
doc += " {\r\n";
doc += "var xfaultcode = event.result.errorDetail.code; \r\n";
doc += "var xfaultstring = event.result.errorDetail.string; \r\n";
doc += "var xfaultsoap = event.result.errorDetail.raw;\r\n";
doc += "// Add code to output error information here\r\n";
doc += "alert(\"xfaultstring\");\r\n";
doc += " }\r\n";
doc += " else if((!event.result.error)&&(" + UniqueID + "_iCallID2==event.result.id))\r\n";
doc += " {\r\n";
doc += "var xmlResult = event.result.raw.xml; \r\n";
doc += " if (xmlResult != \"\" && xmlResult != null)\r\n";
doc += " {\r\n";
doc += "\r\n";
doc += "" + UniqueID + "_MsgXML.loadXML(xmlResult);\r\n";
doc += " " + UniqueID + "_ChatList.innerText = " + UniqueID + "_MsgXML.selectSingleNode(\"//UserList\").text; \r\n";
doc += "" + UniqueID + "_ChatList.scrollTop =2000; \r\n";
doc += " " + UniqueID + "_ChatMsgs.innerHTML += " + UniqueID + "_MsgXML.selectSingleNode(\"//Messages\").text;\r\n";
doc += "" + UniqueID + "_ChatMsgs.scrollTop =2000; \r\n";
doc += " }\r\n";
doc += " window.setTimeout('" + UniqueID + "_iCallID2 = service.ChatWebService.call(\"GetMsgs\"," + UniqueID + "_NickName);',3000);\r\n";
doc += " }\r\n";
doc += "else if((event.result.error)&&(" + UniqueID + "_iCallID3==event.result.id))\r\n";
doc += " {\r\n";
doc += "var xfaultcode = event.result.errorDetail.code; \r\n";
doc += "var xfaultstring = event.result.errorDetail.string; \r\n";
doc += "var xfaultsoap = event.result.errorDetail.raw;\r\n";
doc += "// Add code to output error information here\r\n";
doc += "alert(\"xfaultstring\");\r\n";
doc += " }\r\n";
doc += " else if((!event.result.error)&&(" + UniqueID + "_iCallID3==event.result.id))\r\n";
doc += " {\r\n";
doc += "var xmlResult = event.result.raw.xml; \r\n";
doc += " if (xmlResult != \"\" && xmlResult != null)\r\n";
doc += " {\r\n";
doc += "\r\n";
doc += "" + UniqueID + "_MsgXML.loadXML(xmlResult);\r\n";
doc += " " + UniqueID + "_ChatList.innerText = " + UniqueID + "_MsgXML.selectSingleNode(\"//UserList\").text; \r\n";
doc += " " + UniqueID + "_ChatMsgs.innerHTML += " + UniqueID + "_MsgXML.selectSingleNode(\"//Messages\").text;\r\n";
doc += " " + UniqueID + "_ChatList.scrollTop =2000; \r\n";
doc += " " + UniqueID + "_bnSendMsg.disabled = false;\r\n";
doc += " " + UniqueID + "_ChatMsgs.scrollTop =2000; \r\n";
doc += " " + UniqueID + "_UserInput.value = \"\";\r\n";
doc += " " + UniqueID + "_UserInput.disabled = false;\r\n";
doc += " " + UniqueID + "_UserInput.focus();\r\n";
doc += " }\r\n";
doc += " window.setTimeout('" + UniqueID + "_iCallID2 = service.ChatWebService.call(\"GetMsgs\"," + UniqueID + "_NickName);',3000);\r\n";
doc += " }\r\n";
doc += "} \r\n";
doc += "function SendMsg()\r\n";
doc += "{ \r\n";
doc += "if (" + UniqueID + "_UserInput.value == \"\") return false;\r\n";
doc += "" + UniqueID + "_bnSendMsg.disabled = 'true';\r\n";
doc += "" + UniqueID + "_UserInput.disabled = 'true';\r\n";
doc += "" + UniqueID + "_iCallID3 = service.ChatWebService.call(\"XchangeMsgs\"," + UniqueID + "_NickName," + UniqueID + "_UserInput.value);\r\n";
doc += "} \r\n";
doc += "</script> \r\n";

}
}
}
這里有幾個問題,
1。我們繼承的是Table,記住table等server端控件本身就繼承了control類,我們做控件不一定要直接繼承control
2。[“。。。”]是metadata他是用來做可視化控件的具體含義看msdn
3。我們這里采用client script的方法,可以看出實現方式與asp中大體一致,即Server端“寫”script
4。Dhtml Behavior的應用,Behavior是MS擴展的css元素

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 庆安县| 儋州市| 扶风县| 柘荣县| 米易县| 三原县| 县级市| 宁远县| 咸丰县| 宁城县| 英吉沙县| 永寿县| 尚志市| 花垣县| 汕头市| 历史| 沈丘县| 汉沽区| 英山县| 新竹县| 屏南县| 垦利县| 北川| 澎湖县| 广灵县| 兴城市| 景东| 辽阳市| 西丰县| 石嘴山市| 樟树市| 富裕县| 阿坝| 宜良县| 平塘县| 瑞安市| 海城市| 阿克苏市| 东乌| 阳西县| 旅游|