<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ChatUserControl.ascx.cs"
Inherits="MetamorphismApp.ChatUserControl" %>
<asp:Timer ID="timer1" runat="server" OnTick="timer1_Tick" Interval="5000">
</asp:Timer>
<div id="divChatWindow" class="clChatWindow">
<div>
<asp:Label runat="server" Text='<%# Eval("username") %>' class="divHeader" ID="lblChatFriend"></asp:Label>
<asp:Image ID="imgFriend" runat="server" CssClass="classFriendImage" />
<asp:LinkButton ID="lbClose" runat="server" CommandName="Close" CssClass="lbClose"
OnClick="lbClose_Click">Close</asp:LinkButton></div>
<div class="chatText" id="idChatText" runat="server">
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="Tick" />
<asp:AsyncPostBackTrigger ControlID="btnSendChat" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Repeater runat="server" ID="rpChatMessages">
<ItemTemplate>
<asp:Image ID="imageForFriend" runat="server" CssClass="clFriendsImage" ImageUrl='<%# "HttpImageHandler.jpg?username=" + DataBinder.Eval(Container.DataItem,"fromusername").ToString() %>' />
<asp:Label ID="chatMessage" runat="server" Text='<%# Eval("Message") %>'></asp:Label>
<br>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:TextBox ID="txtChatMessage" runat="server" Width="142px" CssClass="clChatMessage" EnableViewState="true"
TextMode="MultiLine"></asp:TextBox>
<asp:LinkButton ID="btnSendChat" runat="server" CommandName="Insert" CommandArgument='<%# Eval("username") %>'
OnClick="btnSendChat_Click">Send</asp:LinkButton>
</div>
protected void btnSendChat_Click(object sender, EventArgs e)
{
string username = lblChatFriend.Text;
ucc.InsertMessage(Session["username"].ToString(), username, txtChatMessage.Text);
txtChatMessage.Text = "";
}
调用btnSendChat_Click事件处理程序时,txtChatMessage不会变为空白
答案 0 :(得分:-1)
试试这个:
txtChatMessage.Text = string.Empty;
确保文本为null或为空