How to declare a label? Thanks.

S

Shapper

Hello,

I have a label as follows:
<label id="lName" for="name">Name:<input type="text"
id="name"></input></label>

I need to declare the label in my page.aspx.vb so I can access it on
page load. How is it?

Thanks,
Miguel
 
S

Shapper

Yes, I know I forgot the runat="server" but it's still not working.

What I have in my aspx.vb file is:
Protected WithEvents lname As System.Web.UI.WebControls.Label

And then on page load I have:
lname.Text = "Name:"

My HTML is:
<label id="lname" runat="server" for="fname"><input type="text"
size="55" id="fname" name="fname"></input></label>

Well I get this error:
The base class includes the field 'lname', but its type
(System.Web.UI.WebControls.Label) is not compatible with the type of
control (System.Web.UI.HtmlControls.HtmlGenericControl)

I tryied just in case something like:
Protected WithEvents lname As
System.Web.UI.HtmlControls.HtmlGenericControl

Anyway it's not working.

Can somebody please tell me what is wrong here?

Thanks,
Miguel
 
G

Guest

Shapper,

The <label> is an HtmlControl.HtmlGenericControl control whereas the
<asp:Label> is a WebControl.Label control. Seems to me you meant to use the
latter. The <label> tag in html is usually used alongside checkboxes so that
a user can click on the label to select a checkbox.

Simply replace the <label> with <asp:Label> and declare it

Protected WithEvents lname As System.Web.UI.WebControls.Label

I suspect you would want reference the textbox as well. If so use
<asp:TextBox> instead of <input type="text">. And declare it

Protected WithEvents fname As System.Web.UI.WebControls.TextBox


Hope this helps.


Cheng Yuan Yap Ye
http://kuantanzai.blogspot.com
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

it must be <asp:label> as error indicates <label> is a HtmlGenericControl
and <asp:label> is a Label
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top