User control inheritance and properties

  • Thread starter Thread starter hb
  • Start date Start date
H

hb

Situation: A variable is declared with a default value in base user
control. The control that inherits from the control may want to change the
values. Here is how I currently have it set up (condensed to essential
code):

======= BASE USER CONTROL ========
public class Base107RequestSubform : System.Web.UI.UserControl {

protected string _jsEditFunction = "DoNothing();";

public string JavascriptEditFunction {
get {
return _jsEditFunction;
}
}

}

======= INHERITED CONTROL ========
public abstract class DisInf04 : DiscrepancyInfo // DiscrepancyInfo class
inherits from Base107RequestSubform, so DisInf04 is a "grandchild" of
Base107RequestForm
{
new protected string _jsEditFunction = "ToggleDiscrepancyEdit();";
}

======= ASPX PAGE THAT LOADS CONTROL DYNAMICALLY =========
// code is in Page_Init event
// subformClass is a string and it's pulled from DB

discrepancyInfoControl = (_107RequestForm.DiscrepancyInfo)
this.Page.LoadControl( String.Format( "107RequestForm/{0}.ascx",
subformClass ) );
subformPanel.Controls.Add( discrepancyInfoControl );
lnkToggleEdit.NavigateUrl = "javascript: " +
discrepancyInfoControl.JavascriptEditFunction;

===============
So my problem is that the value "ToggleDiscrepancyEdit();" is not being
pulled in this line:
lnkToggleEdit.NavigateUrl = "javascript: " +
discrepancyInfoControl.JavascriptEditFunction;
Instead, it's getting the value "DoNothing();" from the base class. What am
I missing here? I have tried putting that line in other page events, like
Load and PreRender, but nothing has worked so far.
--

Hillarie Branyan
Mercer Engineering Research Center
478.953.6800 x2505
(e-mail address removed)
 
Hi,

you need to override JavascriptEditFunction in DisInf04 to return
diffrent value. you call from page to JavascriptEditFunction and the
only place it implements is on your base class so base class called.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Natty Gur said:
Hi,

you need to override JavascriptEditFunction in DisInf04 to return
diffrent value. you call from page to JavascriptEditFunction and the
only place it implements is on your base class so base class called.

Yes, that's what I ended up doing yesterday. I just assumed I could
override the value the property returns, not the property itself. Oh well,
at least I have it figured it out now.

thanks
 
Back
Top