C# - Inheriting From A System.Web.UI.UserControl Base Class?
Feb 28, 2011
First off, I am wondering if this is possible. I read slight grumblings around the internet about this, but I was not entirely sure.
My scenario: I have a base chart class which has some methods which all charts should have.
public partial class BaseChart : System.Web.UI.UserControl
{
public BaseChart()
{
}
public void ToggleLegend()
{
Chart1.Legends[0].Enabled = !Chart1.Legends[0].Enabled;
}
}
There is also some mark-up for this BaseChart -- setting background colors, etc. All charts which inherit BaseChart should use this starting mark-up and be able to build upon it.
I would then like to do this:
public partial class HistoricalLineChart : BaseChart
{
public HistoricalLineChart()
: base()
{
public HistoricalLineChart(int reportID)
: base()
{
Chart1.Titles[0].Text = "Hello World";
}
}
where HistoricalLineChart is a web user control with no mark-up e.g. "HistoricalLineChart.ascx"
The problem is that Chart1 is undefined when in HistoricalLineChart's scope. Is there something that I am missing here?
View 3 Replies
Similar Messages:
Aug 28, 2010
I have an asp.net usercontrol (ascx) that inherits from an abstract class (that inherits from a UserControl). My Project is in a 3-tier architecture (DAL -> Bll -> UI/Views). Currently there are no class files in the UI layer (other than the code-behinds). Which layer should I add this abstract class to?
View 2 Replies
Feb 5, 2010
I can have a base class for views in an MVC project like this:
public class BaseViewPage : System.Web.Mvc.ViewPage
{
public string Something { get; set; }
}
And then in the ASPX I can do this:
<%@ Page Something="foo" Language="C#" Inherits="MyNamespace.BaseViewPage" %>
This works fine; the problem is when I try to do the same with the generic version:
public class BaseViewPage<TModel> : System.Web.Mvc.ViewPage<TModel> where TModel : class
{
public string Something { get; set; }
}
When I try to use this from the ASPX, like this:
<%@ Page Something="foo" Language="C#" Inherits="MyNamespace.BaseViewPage<SomeClass>" %>
I get the error message:
Error parsing attribute 'something': Type 'System.Web.Mvc.ViewPage' does not have a public property named 'something'.
Notice how it tries to use System.Web.Mvc.ViewPage rather than my BaseViewPage class. To make it more interesting, if I remove the "Something" attribute from the Page directive and put some code in the generic version of BaseViewPage (OnInit for example) the class is actually called / used / instantiated.
So, am I doing something wrong or is this a limitation.
View 1 Replies
Oct 18, 2010
Recently, I tried to get my Web Service class to inherit from a custom base class that inherits from System.Web.Services.WebMethod instead of the System.Web.Services.WebMethod directly.
However, I've been getting Error 500.
Public Class Service1
Inherits BaseClass
<System.Web.Services.WebMethod()> _
Public Function GetSessionID() As String
GetSessionID = Me.Session.SessionID
End Function
End Class
public class BaseClass
Inherits System.Web.Services.WebService
public property Property1 as string
public property Property2 as string
End Class
View 6 Replies
Sep 16, 2010
I have this Control directive in a usercontrol (i've changed the namespace and class name):
<%@ Control Language="C#" AutoEventWireup="true" Inherits="Namespace.Path.To.ClassName" %>
<asp:TextBox runat="server" ID="txtComment" TextMode="MultiLine" ValidationGroup="comment" />
ClassName is a class that lives in a class library and this is the class:
namespace Namespace.Path.To
{
public class ClassName : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox txtComment;
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.Write(txtComment == null);
HttpContext.Current.Response.End();
}
View 3 Replies
Oct 14, 2010
I have defined the following control which serves as a wrapper for another control (simplified code):
[code]....
Can anyone provide any insight as to why it is failing in one environment, but not the others? Is this something related to configuration? The user control is hosted within a "SmartPart" style user control loader which is being used on a WSS 3.0 site in the DIT/SIT/UAT environments.
View 1 Replies
Jun 29, 2010
I am new in asp .net.I am not able to undestand why we call base class method when we
override methods/events.Like automatically visual studio will put base.OnInit() if you are overriding OnInit.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
same is the case of Finalize. In derived we call base.Finalize() Is there any need of calling these base class methods ?
View 2 Replies
Dec 21, 2010
I've written a class that inherits from DataControlField. I did that so I can add a custom column to my gridview. The datasource of my gridview is a SQLDatasource. I now need to get the datatype of each field in my custom class e.g string, boolean, int etc.
View 7 Replies
Jan 19, 2010
If I'm writing in-line code on a .aspx page is it possible to override the onLoad of the class that the .aspx is directly inheriting from? Right now if I do the override the base.onLoad inline on the .aspx page it is overriding the "Page" object's onLoad event not the class the .aspx is inheriting from.
View 1 Replies
Dec 16, 2010
This is my first "request for help" post - I've spent the past few weeks helping others, so I'm hoping someone can shed some light here.I've dealt with server controls before, so it's not new to me, but it was some time ago and I'm a bit rusty. I have an inherited calendar control, that works fine:
[Code]....
I've overriden the Render method, hoping to be able to modify the HTML output of the control - I want to hide the back arrow if the Month & Year in MinDate is reached in the calendar, and the same goes for MaxDate and the forward arrow.On top of this, I want to be able to display icons in the day cells, under certain data-bound conditions. Once I've figured one out, I'm sure I'll be able to work the other one out.Are there any other methods, events or properties more suitable for this? Are there any other controls that do what I'm looking for that I've maybe overlooked?I'm using C#.Net 4.0 Webforms - it's a very small app, so I've not used MVC etc... just a few LINQ queries to the database.
View 2 Replies
Aug 20, 2010
Since we can access the private data member of base class in the derived class with the help of friend function. How can we do the same in C# asp.net? I mean whats the alternative of friend function in C# asp.net
View 2 Replies
Mar 13, 2010
Using the following Webservice definition using aClientArgs as a complex type:
[System.Web.Script.Services.ScriptService]
public class Controller : System.Web.Services.WebService {
[WebMethod]
public void save_client(aClientArgs client)
{
// Save client data
}
}
Then defining aClientArgs as a sub-class:
public class aArgs
{
public string id = null;
public string name = null;
}
public class aClientArgs : aArgs
{
public string address = null;
public string website = null;
}
Returns the following WSDL fragment for the save_client args:
<save_client xmlns="http://tempuri.org/">
<client>
<address>string</address>
<website>string</website>
</client>
</save_client>
When I'm expecting the following:
<save_client xmlns="http://tempuri.org/">
<client>
<id>string</id>
<name>string</name>
<address>string</address>
<website>string</website>
</client>
</save_client>
So it appears that the .NET WebService is not treating inherited properties as arguments/variables for purposes of a web service. How do I get .NET to also use the properties of the base class?
View 1 Replies
Feb 15, 2011
I'd like to inherit all my controllers from a custom base class that I write myself. I can change the line every time I add a new controller, but it would be nicer if I could somewhere specify the default value that gets set there. That way I wouldn't need to worry about forgetting this, and other people who get added to the project later on would have an easier time.
View 3 Replies
Dec 16, 2010
In my MVC project, I am trying to setup a base product class that will be inherited by a more specific class later. Here is my scenario. I have a table called ProductBase, it contains three fields, BaseProductId(PK), CatalogNum, and ListPrice. Every product in the system will share these attributes. Next, I have a table called Shirt, with three fields BaseProductId(PK, FK), Color, and Size.
I then setup an Entity Data Model that pulled in both of these tables and created classes BaseProduct and Shirt. So, in my model, I want to do something like this:
[Code]....
The main problem I have with this, is that if I do any kind of condition on CatalogNum or ListPrice, then my performance goes to crap. One of the main things we will want to do is something like this:
[Code]....
This takes an enormous performance hit, and I suspect it is because the partial class above returns to the database for each shirt.
The other problem I have with this approach, is that I cannot force the properties for the Shirt. What if I make a change to the BaseProduct? What happens when I have multiple product types, will I have to repeat this code? I assume I will need to make a change with the entity data model, but I am unsure where to begin.
View 5 Replies
Mar 1, 2010
i have a base user control (WC1) which inherits from WebUserControl and a child user control (WC2) which inherits from WC1. I added a textBox and a label to WC1 in vs design view not code behind. But all the server controls that i put in WC1 are null and give null pointer exception.I tried to access textBox and label in different events but the all of them are null.
Steps to reproduce the error:
create a web user control called WC1 by add a new item in VS added a textBox and label server control to WC1 in design view of VS and put code behind: var value = txetBox.Text; created another web user control called WC2 by add a new item in VS and change its base class to WC1 in its code behind create a web page by adding a new item in vs and drag WC2 to the design view of the page run the page then you will see the exception for the codebehind in WC1
[code]....
page:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WC2.ascx.cs" Inherits="WebApplication1.WC2" %>
can web server controls of WC1 be instantiated in this case? or can user control inherit from another user control and web server controls of parent user control be carried to its children without worring the layout?
View 1 Replies
Mar 5, 2010
When you create a webpage in ASP.net, the codebase inherits System.Web.UI.Page
Now when I extend the page object to check for SessionExpired for example, I create a new class and inherit from system.web.ui.page, and overwrite some functions.
The problem then is that on each page, I have to replace system.web.ui.page with my custompage class.
Is there a way to extend a class by adding methods or modifying its methods directly (e.g. add the sessionExpired check to System.Web.UI.Page) ?
I'm using .NET 2.0
View 2 Replies
Jan 12, 2010
I want to add a custom base class for all of my web forms. I created a "App_code" folder in my asp.net web project and add a simple base page class like this:
namespace MySite.Web
{
// base page for all the pages that need localization
public class LocalizationPage : System.Web.UI.Page
{
protected override void InitializeCulture()
{
base.InitializeCulture();
}
}
}
And then I try to let asp.net web form to inherit from this base page. I have something like this:
using MySite.Web;
namespace MySite.Public
{
public partial class RegisterPage : LocalizationPage
{
}
}
Now I run into problem where Visual Studio doesn't recognize the LocalizationPage class I created. On the above code snippet, LocalizationPage is not highlighted as a class. And when I try to compile, I got the following error message:
Error 1 The type or namespace name 'LocalizationPage' could not be found (are you missing a using directive or an assembly reference?)
View 1 Replies
Feb 15, 2010
Is it possible for a Controller Base class to access a parameter from an action link and if so how do I access that parameter within my Base Controller?
Action Link:
<%=Url.Action("Area_1419", "Home", new { SectionId = 1})%>
Base Controller Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Website.Models;
namespace Website.Controllers
{
public abstract class CategoriesController : Controller
{
public CategoriesDataContext _dataContext = new CategoriesDataContext();
public CategoriesDataContext DataContext
{
get { return _dataContext; }
}
public void SectionID()
{
int SectionID = Convert.ToInt32(Request.QueryString["SectionID"]);
ViewData["SectionID"] = SectionID;
}
public CategoriesController2()
{
//ViewData["Categories"] = from m in _dataContext.Categories where m.Area_ID == SectionID select m;
//ViewData["Categories"] = from c in DataContext.Categories select c;
}
}
}
HomeContoller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Website.Models;
using Website.ActionFilters;
namespace Website.Controllers
{
[HandleError]
public class HomeController : CategoriesController
{
public ActionResult Index()
{
return View();
}
public ActionResult About(int? SectionID)
{
//ViewData["Message"] = SectionID;
return View();
}
public ActionResult Area_1419(int SectionID)
{
return View();
}
public ActionResult Admin()
{
return View();
}
}
}
View 2 Replies
Feb 24, 2011
A client of mine developed a base page for their site from System.Web.UI.Page. Unfotunately in the OnInit override they forgot to call base.OnInit().Every page in the web site inherits from this base page class. So this requires them to test their complete site again to release the fix. This is a time consuming process to do a full regression test. Looking for insight into how urgent they should be to release this obvious fix. My opinion is this is a serious issue.Web search didn't really lead me to actually what goes wrong in the base Page class when this is done. I realize default event delegate won't get initialized.I know it is bad, but how bad?Looking into insight of what issues it can cause? How will this cause havoc with the ASP.NET web controls?Will controls down rev to emitting HTML and/or javascript for older browsers by default?
View 2 Replies
Apr 2, 2010
I am successfully injecting base class properties with spring.net with just a class that inherits from a base abstract class. Lets say Class MyClass : MyBase, and I am successfully setting a property like this:
<object id="myInstantiableClass" type="myAssembly.MyClass myAssenbly" abstract="true">
<property name="MyBaseClassProperty" ref="anotherObjRef"></property> </object>
Where MyBaseClassProperty is a property on the base class. Now I have another abstract class between the old base class and the instantiable class and I am trying to set properties on both the abstract classes. So MyClass : MyNewBaseClass and MyNewBaseClass : MyBaseClass. I have an additional property on the new base class (MyNewBaseClassProperty) and I am trying to inject it like this:
<object id="myInstantiableClass" type="myAssembly.MyClass myAssenbly" abstract="true">
<property name="MyBaseClassProperty" ref="anotherObjRef"></property>
<property name="MyNewBaseClassProperty" ref="someOtherObjRef"></property>
</object>
The property on the old base class is being injected but the one on the new one is not - and I am not getting an error or anything (so I am pretty sure my config is good), that property is just null! I am on asp.net (not MVC) and the class MyClass is a user control (ascx).
View 1 Replies
Apr 29, 2010
I have the following PerformanceFactsheet.aspx.cs page class
public partial class PerformanceFactsheet : FactsheetBase
protected void Page_Load(object sender, EventArgs e)
// do stuff with the data extracted in FactsheetBase
divPerformance.Controls.Add(this.Data);
where FactsheetBase is defined as
public class FactsheetBase : System.Web.UI.Page
[code]...
View 3 Replies
Sep 29, 2010
In my controller have a FormViewModel which inherits from a domain class declared in dbml. In the constructor of the FormViewModel I want to do a shorthand assignment to the inherited class properties with the passed in object (ie thisPerson) without iterating through each property of the inherited class and assigning its value with corresponding property in the passing in object. Should I use super, base, this, or something else?
[code]....
View 1 Replies
Oct 18, 2010
I'm trying to have all my views inherit from a custom class so that I can add certain behaviour and values to all pages, but I'm having some issues. I tried subclassing System.Web.Mvc.WebViewPage but I'm forced to implement an Execute procedure that I don't know what it should do. Also, if I try to access the Context variable, I get a null reference (really weird). This leads me to think that I may have the wrong base class.
View 1 Replies
Mar 8, 2011
We have a base class that all our webpages in our application inherit from. I have a static method in the base class which when called will clear values from the application cache. Now the issue is this method needs to be triggered from a source outside the current application. I there any way this can be accomplished without creating an aspx page that will call this base method on page load.
View 1 Replies
Nov 16, 2010
I have the following classes (pseudocode):
Item ( int Field1 )
ItemDetail : Item (int Field2, string field3)
If I set ItemDetail as the datasource for an asp.net gridview:
grid.DataSource = new List<ItemDetail>();
grid.DataBind();
Can I use Field1 in the GridView? If so, what is the correct DataBinder syntax? The following code blows up trying to cast to an Item:
<%# DataBinder.Eval(Container.DataItem, "Field1") %>
EDIT: And I'm a moron. I had copied the gridview and was calling a RowDataBound event handler for a different grid... Sorry to have wasted everyones time, but there is some good info here regardless if anyone has the same question. In the end, the public properties of the base class are binding correctly.
View 2 Replies