Link to home
Start Free TrialLog in
Avatar of kdunnett
kdunnett

asked on

asp:panel and adding text

Hey all,

Is there a way of programmically adding strait text to an asp:panel from server side via c#?

For instance, to mimic this:
<asp:Panel ID="pnlTemp" Visible="False" Runat="server">
     ADD THIS TEXT RIGHT HERE
</asp:Panel>

pseudo code:
(from a datagrid)
Panel temp  = (Panel) e.Item.FindControl("pnlTemp");
temp.<some attribrute to add text to a panel>.text = "ADD THIS TEXT RIGHT HERE";
Avatar of CtrlAltDl
CtrlAltDl
Flag of United States of America image

Unfortunately there is no text property for a Panel (that would make it too easy!), so you have to add a Literal Control like this:

LiteralControl lcTemp = pnlTemp.Controls[0] as LiteralControl;
lcTemp.Text = "ADD THIS TEXT RIGHT HERE";
ASKER CERTIFIED SOLUTION
Avatar of DBAduck - Ben Miller
DBAduck - Ben Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've always just drag-n-dropped a empty literal control in the gui designer.  I'm too lazy to create controls via code. ;-)
Avatar of kdunnett
kdunnett

ASKER

dbaduck,
That worked perfectly...  Thanks for your help.