Custom Control

S

shapper

Hello,

I have a custom control named Parent where I used the following:

Protected Overrides Sub CreateChildControls()
...

MyBase.Controls.Add(MyTextBox)
MyBase.CreateChildControls()
Me.ChildControlsCreated = True
End Sub

Public Overloads Overrides Sub RenderBeginTag(ByVal writer As
HtmlTextWriter)
If Me.ClientID <> Nothing Then _
writer.AddAttribute(HtmlTextWriterAttribute.Id, Me.ClientID)
If Me.CssClass <> Nothing Then _
writer.AddAttribute(HtmlTextWriterAttribute.Class,
Me.CssClass)
writer.RenderBeginTag(HtmlTextWriterTag.Div)
End Sub

Public Overloads Overrides Sub RenderEndTag(ByVal writer As
HtmlTextWriter)
writer.RenderEndTag()
End Sub


Now I created a new control named Child which inherits from Parent.

In this control I need to do two things:

1. Add a new control, a label.

2. Make CssClass = "MyChildCssClass" IF Me.CssClass = Nothing.

I am having problems with making this happen.

I tried to create CreateChildControls and RenderBeginTag in my Child
control that inherits from my Parent control but something is going
on.

I am not able to "merge" the control adding and attributes from my
Parent control and my Child control.

How should I do this?

Thanks,

Miguel
 
S

shapper

Hello,

I have a custom control named Parent where I used the following:

Protected Overrides Sub CreateChildControls()
...

MyBase.Controls.Add(MyTextBox)
MyBase.CreateChildControls()
Me.ChildControlsCreated = True
End Sub

Public Overloads Overrides Sub RenderBeginTag(ByVal writer As
HtmlTextWriter)
If Me.ClientID <> Nothing Then _
writer.AddAttribute(HtmlTextWriterAttribute.Id, Me.ClientID)
If Me.CssClass <> Nothing Then _
writer.AddAttribute(HtmlTextWriterAttribute.Class,
Me.CssClass)
writer.RenderBeginTag(HtmlTextWriterTag.Div)
End Sub

Public Overloads Overrides Sub RenderEndTag(ByVal writer As
HtmlTextWriter)
writer.RenderEndTag()
End Sub

Now I created a new control named Child which inherits from Parent.

In this control I need to do two things:

1. Add a new control, a label.

2. Make CssClass = "MyChildCssClass" IF Me.CssClass = Nothing.

I am having problems with making this happen.

I tried to create CreateChildControls and RenderBeginTag in my Child
control that inherits from my Parent control but something is going
on.

I am not able to "merge" the control adding and attributes from my
Parent control and my Child control.

How should I do this?

Thanks,

Miguel

Hi,

Basically I have the following:

Public Class Parent
Inherits WebControl
Implements INamingContainer

Protected Overrides Sub CreateChildControls()
...
End Sub ' CreateChildControls

Public Overloads Overrides Sub RenderBeginTag(ByVal writer As
HtmlTextWriter)
...
End Sub ' RenderBeginTag

Public Overloads Overrides Sub RenderEndTag(ByVal writer As
HtmlTextWriter)
...
End Sub ' RenderEndTag

And:

Public Class Child
Inherits Parent

In Child I need to also add controls and define attributes as it is
done in CreateChildControls and RenderBeginTag of Parent.
For example:
Add TextBox1 in Parent and TextBox2 in child
Define Width attribute in Parent and CssClass in child.

Until now I wasn't able to do this. I did a few changes in overload
and overriding of those methods but I wasn't able to make this work.

How can I do this?

Thanks,
Miguel
 
J

jx.su.go

Hello,

I have a custom control named Parent where I used the following:

Protected Overrides Sub CreateChildControls()
...

MyBase.Controls.Add(MyTextBox)
MyBase.CreateChildControls()
Me.ChildControlsCreated = True
End Sub

Public Overloads Overrides Sub RenderBeginTag(ByVal writer As
HtmlTextWriter)
If Me.ClientID <> Nothing Then _
writer.AddAttribute(HtmlTextWriterAttribute.Id, Me.ClientID)
If Me.CssClass <> Nothing Then _
writer.AddAttribute(HtmlTextWriterAttribute.Class,
Me.CssClass)
writer.RenderBeginTag(HtmlTextWriterTag.Div)
End Sub

Public Overloads Overrides Sub RenderEndTag(ByVal writer As
HtmlTextWriter)
writer.RenderEndTag()
End Sub

Now I created a new control named Child which inherits from Parent.

In this control I need to do two things:

1. Add a new control, a label.

2. Make CssClass = "MyChildCssClass" IF Me.CssClass = Nothing.

I am having problems with making this happen.

I tried to create CreateChildControls and RenderBeginTag in my Child
control that inherits from my Parent control but something is going
on.

I am not able to "merge" the control adding and attributes from my
Parent control and my Child control.

How should I do this?

Thanks,

Miguel

I think you missing the key 'base'.
if you want to use the parent method. you should call the base method.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top