Ho to inherit a webuser control from another webuser control

I wantto inherit a webuser control from another webuser control and in the base webuser control i should have some functions which will be inherited by the other webuser control. How could i do that? 

Thanks in advance.

0
kem06
4/23/2009 6:43:10 AM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

7 Replies
804 Views

Similar Articles

[PageSpeed] 53

 Depending on what you want - you could put the master user control inside the child user control and let it maniuplate it that way.

0
rtpHarry
4/23/2009 7:14:13 AM

Well actually i need to use some properties, methods and fields of base webusercontrol on several othe child webusercontrols. And i want the child webusercontrols to extend to the base websuercontrol just like polymorphism. And i don't wantto drop base webusercontrol onto chiled ones each time.

0
kem06
4/23/2009 7:55:41 AM

 Try these resources:


Or depending on what you are attempting you might find it easier to just put this standard functionality in a helper class that you can call from any usercontrol?
0
rtpHarry
4/23/2009 11:20:37 PM

Thanks, however all those links are not really relevant to what i am looking for. The followings are wht i have done so far:

Base WebUserControl's code behind is:

public partial class WebUserControlBase : System.Web.UI.UserControl

{

//protected void Page_Load(object sender, EventArgs e)

//{

//}

private string Name = "KEMAL";

public string NAME { get { return Name; } set { Name = value; } }

public string Metod(string Ad)

{

return Ad + " " + "ESMER";

 

}

 

}

Base WebUserControl's HTML is:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControlBase.ascx.cs" Inherits="WebUserControlBase" ClassName = "MyControls.UstControl" %>

<table border="0" cellpadding="0" cellspacing="0" style="width: 536px">

<tr>

<td>

</td>

<td>

<asp:Label ID="Label1Base" runat="server" Text="Ad-Base"></asp:Label>

&nbsp;

</td>

<td>

<asp:TextBox ID="TextBox1Base" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td>

</td>

<td>

<asp:Label ID="Label2Base" runat="server" Text="Soyad-Base"></asp:Label></td>

<td>

<asp:TextBox ID="TextBox2Base" runat="server"></asp:TextBox>&nbsp;

</td>

</tr>

<tr>

<td style="height: 19px">

</td>

<td style="height: 19px">

</td>

<td style="height: 19px">

<asp:Button ID="Button1Base" runat="server" Text="Button" /></td>

</tr>

</table>

 

Code behind of the Inherited WebUserControl from the base WebUserControl above is:

 

public partial class WebUserControlDerived : MyControls.UstControl

{

protected void Page_Load(object sender, EventArgs e)

{

//this.NAME = "Kemal";

 

}

protected void Button1Derived_Click(object sender, EventArgs e)

{

TextBox1Derived.Text =
this.NAME;

TextBox2Derived.Text = this.Metod(this.NAME);

this.Calendar1.SelectedDate=DateTime.Today ;

}

}

 And HTML of this inherited child WebUserControl is:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControlDerived.ascx.cs" Inherits="WebUserControlDerived" %>

<table border="0" cellpadding="0" cellspacing="0" style="width: 536px">

<tr>

<td>

</td>

<td>

<asp:Label ID="Label1Derived" runat="server" Text="Ad-Derived"></asp:Label>

&nbsp;

</td>

<td>

<asp:TextBox ID="TextBox1Derived" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td>

</td>

<td>

<asp:Label ID="Label2Derived" runat="server" Text="Soyad-Derived"></asp:Label></td>

<td>

<asp:TextBox ID="TextBox2Derived" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td style="height: 19px">

</td>

<td style="height: 19px">

</td>

<td style="height: 19px">

<asp:Button ID="Button1Derived" runat="server" Text="Button" OnClick="Button1Derived_Click" />

<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td>

</tr>

</table>

 

The problem is that.: Although i say  "public partial class WebUserControlDerived :MyControls.UstControl" there in inherited WebUserControl's code behind, MyControls.UstControl is not recognized by .NET, thus i cannot see the properties, methods and fields of base WebUserConbtrol, when i say "this."  . Intellisense wouldn't list all the inherited metods fileds and properties etc from the base WebUserControl. I couldn't figure out why.

Thanks...

0
kem06
4/24/2009 7:04:49 AM

Hi,

When inheriting user control the ascx could not be inherited. You have to copy&paste all the code from parent user controls's ascx to the child user control's.

 Or you can use custom control instead.

 


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
4/24/2009 7:41:30 AM

Allen Chen – MSFT:

Hi,

When inheriting user control the ascx could not be inherited. You have to copy&paste all the code from parent user controls's ascx to the child user control's.

 Or you can use custom control instead.

 

Well, i already inherited the codebehind of the master WebUserControl. What do you exactly mean when you say "When inheriting user control the ascx could not be inherited".  Do you mean i cannot inherit the HTML side of the WebUserControl. And what is a custom control?

0
kem06
4/24/2009 8:07:13 AM

kem06.net:
Do you mean i cannot inherit the HTML side of the WebUserControl.

Yes.

kem06.net:
And what is a custom control?

Please refer to:

http://support.microsoft.com/kb/893667


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
4/24/2009 9:28:08 AM
Reply:

Similar Artilces:

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Controls.Add in Composite Control that inherits another control
Hi! I created a composite control that inherits from the WebControls.Button. I added the following in the Load event:         Dim mHidden As New WebControls.HiddenField        Me.Controls.Add(mHidden) but the control is not created. Why?Dimitris PapadimitriouSoftware Development Professional Hi,Child controls on Button do not make much sense (how would you expect them to be rendered, doesn't button allow only text into value attribute?). Button allows child controls to be added, but they won't be rendered b...

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this?  AllAboutFocus.com. Information Technolo...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingcompositecontrols.asp Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Trying to load a control into a control from another control
Exactly as the subject states, I'm trying to load a control into another control from a control loaded into a page, I keep getting this error from the code I have below. I've also tried the findcontrol but it keeps coming up null. (67): 'System.Web.UI.UserControl' denotes a 'class' where a 'variable' was expected UserControl ut = ((webcontrols.BrowseItems)UserControl).LoadControl("BrowseItems"); ((webcontrols.BrowseItems)UserControl).pnl_browse_main.Controls.Add(ut); This is how we Load User controls into a content place holder. try { UserCont...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. http://forums.asp.net/p/1397433/3010100.aspx#3010100 I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal asp.net page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer asp.net sites and/or SharePoint sites why don't you just create Web Par...

Custom Server Control with Child Controls
I have a custom server control <xx.Parent... /> which parses custom child controls <xx.Child... />. In Visual Studio 2008, IntelliSense shows me both when I start typing my control namespace. How can I prevent the child control from showing up in IntelliSense  unless I'm adding it within the parent tags?Thanks. --Rudy...

Custom Server Control With Child Control
All, I am currently putting together a very simple control. The new control outputs a table with two rows. The top row contains a heading and the bottom row will contain any other content. The control as it stands works perfectly well and I can place text into the content row no problem. Now, to the problem. Once I'd completed the control I figured it would be neat to enable the developer to add controls directly into the bottom row (content row) of the outputted table. As you probably know the WebControl class has a Controls collection which the developer can use to add any other...

Custom Web Control inside another Custom Web Control
Hi I created a custom web control (CusWebNew) that displays some textboxes by adding them to the ControlCollection of the webcontrol. I also created a custom webcontrol (CustWebButton) that inherts from Button control, and overrided the OnClick function. When I use CustWebButton on a regular web form, it seems to function correctly. However, when I added to be part of the ControlCollection of CustWebNew, it stops to work.   Any ideas why? Thanks Hey, What do you mean by stops to work?  Explain what you are trying to do with it and what it doesn't do.Brian"Trust in the...

Web Server Control Containing another Web Server Control?
I'm building a web server control that needs to include functionality from 3rd party web server control, ASPNetMenu. My web server control needs to render ASPNetMenu at runtime to create a menu. I'd like to do this so that my control's parent ASPX page does not need to register ASPNetMenu or make any configuration changes as this should be done through my web server control. Does anybody have any suggestions on how to do this? Mike - Cache entire web sites at the client and server and keep cache current. Cache just got easier! There are two articles that you would want to be int...

server-side control inside another server-side control
Hi everyone. I have a requirement where I need to create a custom server side control which will contain a series of ASP controls -- no problem there. However, this component also needs to itself be placed inside a server side control, and then placed into the page...so I'll have a custom server-side component inside a custom server-side component. Is that even possible? Everytime I start to think about it I get a headache. Thanks Matt  It's perfectly possible. Just give it a try and you'll see that it works.-- "Mark As Answer" if my reply helped you -- Yup...

Web resources about - Ho to inherit a webuser control from another webuser control - asp.net.custom-server-controls

Inherit the Wind (play) - Wikipedia, the free encyclopedia
Henry Drummond, Matthew Harrison Brady, E. K. Hornbeck, Bertram Cates, Rachel Brown, Rev. Jeremiah Brown Inherit the Wind is a play by Jerome ...

Inherit The Wind - Spencer Tracy Speech - YouTube
A favorite scene from one of my favorite films, INHERIT THE WIND.

Bobbi Kristina Brown death: who will inherit Whitney Houston's millions?
Now that Bobbi Kristina Brown is gone, six months after she mysteriously fell into unconsciousness, what happens to the estate she was to inherit ...

Leighton inherits bulk of NBN contracts
Construction giant Leightons has emerged with a large slice of NBN Co contracts, following ownership changes at contracting firm Silcar.

Inherit the wind: dinosaurs blamed for changing climate
Inherit the wind: dinosaurs blamed for changing climate

Who inherits your Facebook when you die?
US plan to automatically give loved ones access to a deceased person's digital accounts.

New government will inherit a money pit
I AM pretty sure I have bad taste in movies because I rather enjoyed The Money Pit, starring Tom Hanks and Shelley Long.

Prince William and Prince Harry to inherit Princess Diana's wedding dress
Prince William and Prince Harry are set to inherit their mother Princess Diana's wedding dress, just in time for Harry's 30th birthday.

Millionaire Monkey: Primate set to inherit millions
A monkey in India is set to inherit millions of dollars. His adopted owners say the monkey has brought them prosperity and they are paying it ...

Should Children Inherit Parents' LinkedIn Accounts? - Sulemaan Ahmed
Recently, it dawned on me that LinkedIn (and possibly other social networks) might consider allowing their members children to inherit their ...

Resources last updated: 12/12/2015 9:15:56 AM