label.attributes.add

Posted by Ragha under ASP.NET on 5/1/2008 | Views : 13942 | Status : [Member] | Replies : 1
how to access the text property of a label using attributes.add

actually i have written the following code

THIS code is written in .cs file where iam trying to get reference of the control from the .aspx page

HttpContext.Current.Session["selected"] = dt;
Page page = HttpContext.Current.Handler as Page;
WebControl testcontrol = (WebControl)page.FindControl("lblHierarchy");

testcontrol.Attributes.Add("Text","sometext");


the above code works fine but the text is shown as "" (blank)

any help would be appreciated

thanks




Responses

Posted by: SheoNarayan on: 5/1/2008 [Administrator] HonoraryPlatinum

Up
0
Down
Control.Attributes.Add method is used to add the client side attribute of the control not server side property.

In this case suppose you WebControl has a property called Text and simply use
testcontrol.Text = "SomeText";

// Adding client side attribute. This will not display anything but add Text attribute of the span tag like <span id="txtTest" text="fdasfd">RAN</span>

Label lbl = (Label) Page.FindControl("txtTest");
lbl.Attributes.Add("text", "fdasfd");

// Adding server side attribute
lbl.Text = "RAN";

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response