[ASP.NET] Inheritance and Label

R

RicercatoreSbadato

hi all, i'd like to inherit from a label, how can I do ?

i've tried:

1. making a new Web User Control, then inherit from
System.Web.UI.WebControls.Label but not works!
2. creating a class (.cs file) that inherits from the Label Control
but it didn't work!

any idea ?
 
M

Masudur

hi all, i'd like to inherit from a label, how can I do ?

i've tried:

1. making a new Web User Control, then inherit from
System.Web.UI.WebControls.Label but not works!
2. creating a class (.cs file) that inherits from the Label Control
but it didn't work!

any idea ?

Hi...


if you want to extent a asp.net server control you got to create a new
custom control
which inherits from label...
for this add a new custom web control project in vs... and then try...

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
R

RicercatoreSbadato

i've done so (but it doesn't work!)

--
public partial class SuperLabel : System.Web.UI.WebControls.Label
{
protected void Page_Load(object sender, EventArgs e)
{
base.Text += "..inherited";
}
}
--

do you have tried it?
i think you have never tried it..

could you post me a working example ?
 
M

Masudur

i've done so (but it doesn't work!)

--
public partial class SuperLabel : System.Web.UI.WebControls.Label
{
protected void Page_Load(object sender, EventArgs e)
{
base.Text += "..inherited";
}}

--

do you have tried it?
i think you have never tried it..

could you post me a working example ?

Hi...

here is a complete set of tutorials... how to develop a custom server
control...
http://msdn2.microsoft.com/en-us/library/yhzc935f.aspx


Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
R

RicercatoreSbadato

tnx for your support but don't reply only to say something.
my question is precise: I'D LIKE TO CREATE A CONTROL TAHT INHERITS
FROM A LABEL,
then: are you able to do it ? If yes, could you post me a little
example ?
 
M

Masudur

tnx for your support but don't reply only to say something.
my question is precise: I'D LIKE TO CREATE A CONTROL TAHT INHERITS
FROM A LABEL,
then: are you able to do it ? If yes, could you post me a little
example ?

Hi..

Okay here is a code sample...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyCustomLabel
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebCustomControl1 runat=server></
{0}:WebCustomControl1>")]
public class WebCustomControl1 : Label
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Text"] = value;
}
}

protected override void RenderContents(HtmlTextWriter output)
{
output.Write(Text + "FromMunnacs");
}
}
}

this works... i have tested it...

here what i did...
first add a web control library from vs project templete...
then changed the
public class WebCustomControl1 : WebControl
to
public class WebCustomControl1 : Label

ofcourse i changed the rendercontent....

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
P

Patrice

Please always post the error message you get.

The Page_Load event belongs to the Page object not to the Label object so
your code is never called (basically you created a new method that is not
used by ASP.NET).
 
R

RicercatoreSbadato

ok, tnx but can you show me the ASCX side ? i receive an error from my
debugger..
 
M

Masudur

Please always post the error message you get.

The Page_Load event belongs to the Page object not to the Label object so
your code is never called (basically you created a new method that is not
used by ASP.NET).

Hi,

why do you have to use a page load in custom server control...
you dont have to put any page load method...
"RenderContents" method is doing your job....

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
R

RicercatoreSbadato

i don't use the Page_Load() anymore. but the debugger says to me that
the ascx file inherits from a bad source.. could you show me the
source of you ascx file?
tnx.
 
M

Masudur

i don't use the Page_Load() anymore. but the debugger says to me that
the ascx file inherits from a bad source.. could you show me the
source of you ascx file?
tnx.

Hi...

oh i got it... you are trying all these things in a ascx file, that
is... in a usercontrol, right?...
as i mentioned before you got to create a custom web control
Library...

steps...

1. Right Click on your solution file...
2. Select Add ->New Project ...
3. Now Select Web Control Library from Visual c# Project templates...
4. By default vs2005 will create the necessary files for you....

you use your control...
first compile...
and then add to your vs2005 toolbox..
and then drag and drop just like other asp.net controls...

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
R

RicercatoreSbadato

there is a misunderstanding.. when U create a WebUserControl the VS
Environment creates a ascx file too..
 
M

Masudur

there is a misunderstanding.. when U create a WebUserControl the VS
Environment creates a ascx file too..

Hi....

""when U create a WebUserControl the VS Environment creates a ascx
file too.""

we are not creating webusercontrol... we will be creating a custom
control... custom control will not have any .ascx file only a class
file....

i am reaping the steps again...

steps...

2. Select File - > Add ->New Project ...
3. Now Select Web Control Library from Visual c# ->Windows.....
Project templates...
4. By default vs2005 will create the necessary files for you....


Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
R

RicercatoreSbadato

ok, now I have understood.

1.
when I have a label I can write inside it. with my Custom Control how
can i read the inner text ? for example i'd like to read "ciao ciao
ciao", how can i do it? the Text properties doesn't work..

<cc1:webcustomcontrol1 id="WebCustomControl1_1"
runat="server">
ciao ciao ciao
</cc1:webcustomcontrol1>

2.
is there a way to create a Custom Control whitout create a NEW
project? i'd like to create a custom control from my WebSiteProject..

tnx for the help.
 
P

Peter Bucher [MVP]

Hi Ricercatore

is there a way to create a Custom Control whitout create a NEW
project? i'd like to create a custom control from my WebSiteProject..
yes, of course
you can simply add a new Class file to your project, whitch includes the
customcontrol code
for later implementing on your ASPX Page, you have to refer to the Assembly
Name of your Website / Webapplication Project, on the Page Register
Directive.
 

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,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top