0
<%@ 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 不会变为空白

4

1 回答 1

-1

尝试这个:

txtChatMessage.Text = string.Empty;

确保文本为空或为空

于 2012-07-26T10:17:38.703 回答