Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
<asp:Panel ID="PanelFL" runat="server"  >
            <asp:Button ID="chatFLclose" runat="server" Text="Close" />
            <div id="DivChat" >

            </div>
            <asp:TextBox ID="txtChat" runat="server"></asp:TextBox>
            <asp:Button ID="btnSend" runat="server" Text="Send" onclick="btnSend_Click" />
        </asp:Panel>



How i access div from panel and write text on button click event.?
Posted
Updated 22-May-15 16:40pm
v2
Comments
Schatak 23-May-15 0:58am    
You means you want to find 'btnSend'?

Hi,

The DIV element in your panel is an HTML control so you cannot access it directly. To access it in code behind you need to decorate it with runat="server" attribute.
XML
<asp:Panel ID="PanelFL" runat="server"  >
   <asp:Button ID="chatFLclose" runat="server" Text="Close" />
   <div id="DivChat" runat="server" > </div>
   <asp:TextBox ID="txtChat" runat="server"></asp:TextBox>
   <asp:Button ID="btnSend" runat="server" Text="Send" onclick="btnSend_Click" />
</asp:Panel>

and you can get access it now as below -
C#
protected void btnSend_Click(object sender, EventArgs e)
{
   DivChat.InnerText = txtChat.Text;
}
 
Share this answer
 
Use a literal inside the div

XML
<div id="DivChat" >
    <asp:Literal ID="LiteralText" runat="server"/>
</div>


then in your code behind

LiteralText.Text = "Hello world";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900