Thursday, March 22, 2012

HTML control-LABEL

I have several HTML controls -- "Label" in the page. They are used to show some names and content of the page. I want to be able to change the text of these Labels at the run time. Is it possible? I don't see any property of the Label allow me to change the text of the Label. Only at the design time, I can click on the Label to change the text of the Label, I am wondering if I am on the right track Since the design is from the previous graphic designer, I try not to change the type of control. If Label is the wrong choice, what other controls have the similar features to suite my purpose? Thanks.

Chia

Have you tried label.text ?

try declaring the labels as global variables, like so:

ProtectedWithEvents idOfYourLabelAs System.Web.UI.WebControls.Label

then set the text property of the label:

idOfYourLabel.Text = "Your text goes here"


If I use Web control, I have no problem to change the text by doing

Label.text = name;

But, I am using HTML control. There is no such property for me to modify the text.

Thanks,

Chia


Is there any reason that you are not using the label web control ?

What you have to remember is that any procedures that you define in an ASP.Net page are executed server-side. And, when you want to manipulate a control via server-side code, you need to define the tag with an id and a runat="server" statement.

You can try doing this with your html label tag, I'm not sure if it will work though.

Let us know what happens.

Cheers

Martin


Use theInnerTextproperty of the html control.

It works. By using property "InnerText", I can change the text at the run time for HTML control -- Label.

Like I mentioned earlier, the graphic designer was using lots of HTML control -- Label to format and design the screen. I am just trying not to make too much changes of the page format. Also, I am not sure if he has good reason to use HTML control -- Label here.

Chia

No comments:

Post a Comment