Posted by Ragha under ASP.NET on 5/1/2008 | Views : 11257 | 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");


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

any help would be appreciated



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

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";

Sheo Narayan

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

Login to post response