C# - What Layer Does A UserControl's Base Class Belong
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?
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() {
My repositories throw exceptions (System.Exception) when some things go bad and I know this is bad practice.. so i will create a custom exception (DataException). My question is should this custom ex class be in the repository layer or the domain layer? Im thinking it should be in Domain layer where all business objects and repository interfaces live but just want to make sure.
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.
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
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?
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.
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.
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?
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 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?)
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(); } } }
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:
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:
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).
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]...
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?
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.
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.
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.
I'm new to web dev. and I'm using asp.net/C# to build a website. I currently have a class called DataLayer that I'm using to perform all of my database functions, and also store some queried information. I initially had this class as static, because that's how I wanted it to behave, but then realized that will be all kinds of bad for multiple users.
I have to make an instance out of this class in order to use it, but I need to maintain the same instance throughout several webpages for that user. Any thoughts or ideas on how to go about this approach? How to pass this object from page to page? Store in session variable, as a global object somehow?
I've tried setting the <pages pageBaseType="DynamicWebPage" /> value in web.config, but when I response.write out the page type, I'm still getting Microsoft.WebPages.WebPage.
I'm simply trying to sub-class WebPage and add some additional functionality such as a dynamic PageData dictionary similar to Phil Haack's dynamic ViewData dictionary.
it's possible to put the database connection settings into a base page class so that I can auto-init them on a page. like this document: [URL] but with instructions in VB.net
I have the below structure. Admin_note --> AdminBasePage --> System.Web.UI.Page.But Page_Load does not call in AdminBasePage when calling page_load in Admin_note class.Do you know how to solve??
Then I have page that would has a list of ForumPost(s) and and edit option, all on one page. To achieve this I've created a CommentsViewModel that extends "ForumPost" class like so:
[Code]....
This way on my view I can have a list of ForumPost(s) and a form that would edit the post.This is what i see in the debug mode right before the save call:The problem is that when I try to Save/Update I get the following error:I already tried doing this:
[Code]....
with no luck. for some reason downcasting doesn't work and the model or row are still of type CommentsViewModel instead of ForumPost