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 |
![]() |
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 |
![]() |
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 |
![]() |
Try these resources:
![]() |
0 |
![]() |
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> </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> </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> </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 |
![]() |
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 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.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 |
![]() |