asp.net - How to inherit a UserControl from another UserControl? -


is possible inherit user control user control?

the thing i'm trying achieve user control inheriting user control. have baseusercontrol.ascx, , has text "stuff". have user control, childusercontrol.ascx inheriting off of baseusercontrol.ascx. if don't change in childusercontrol.ascx, expect baseusercontrol.ascx text display of "stuff".

and should able extend base user control functionalities in derived one.

i have tried this, not enough in case.

now childusercontrol.ascx looks lie below

<%@ control language="c#" autoeventwireup="true" codefile="childusercontrol.ascx.cs" inherits="test_childusercontrol" %> <%@ register src="baseusercontrol.ascx" tagname="baseusercontrol" tagprefix="uc1" %> 

childusercontrol.ascx.cs below

public partial class test_childusercontrol : baseusercontrol {     protected void page_load(object sender, eventargs e)     {      }    } 

when browse page im getting error as

object reference not set instance of object. description : unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code. exception details : system.nullreferenceexception: object reference not set instance of object. 

any clue?

i have tested situation myself. you can not inherit base class usercontrol it's own ascx code.

what can however, implementing basic functionality in (possibly abstract) base class (without ascx) this:

public class baseclass:usercontrol {     public string basegreeting { { return "welcomebase!"; }} } 

and use methods , properties of base class in concrete usercontrol classes have own ascx file.

public partial class childusercontrol : baseclass {     protected override void oninit(eventargs e)     {         base.oninit(e);         greeting = base.basegreeting; //as initial value     }     public string greeting     {         { return labelgreeting.text; }         set { labelgreeting.text = value; }     } } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -