How to get text attribute from asp panel:

Probably a simple question, but now I look through 30 minutes and STILL cannot find a solution!

I have a panel and it has the text = "something" attribute. but the panel class doesn't seem to have a getAttribute method ... Which personally, I think, is STUPID!

Code follows:

foreach (Control c in clientGrid.Controls)
{
    if (c.GetType().ToString().Equals("System.Web.UI.WebControls.Panel"))
    {
        /*Something*/ textInsidePanel = ((Panel)c)./*Somthing*/              
    }
}

Now I have tried AttributeCollection text = ((Panel)c).Attributes;

and

string text = ((Panel)c).Attributes.toString();

and other useless things ...

It should be very simple! when I check an element on chrome, I see a panel, (well, a div), and I see a text attribute right there. and I see its value! but I want my C # code to matter!

Please, help!

Alex

+3
source share
3 answers

if I get the question correctly - you can use the following code

part of asp

<asp:Panel runat="server" ID="pnl" Text="hello world"></asp:Panel>

C # part -

string s = pnl.Attributes["Text"];
+4

?:

string val = YourPanel.Attributes["Text"];
//                                   ^ that your attribute name

> . , , ( , script). - .

+2

The control panel itself does not have the text property. But if you access the inner text as LiteralControl, it will work:

var panelContent = ((Panel)c).Controls[0] as LiteralControl;
var text = panelContent.Text;
-1
source

All Articles