C# - Returning Custom Class From DAL?
Mar 25, 2011
I have an object with following attribute Books ---------- ID , Name
Now, I want to return an object for a gridview in presentation layer which has a lot more attributes then the original object
I don't have any business object composed of these attributes currently & I don't want to create it just for the sake of a gridview.
How do I create & return custom objects like these on the fly ? I am new to DTO's. Can someone give me an example to return a DTO inside my DAL ?
View 3 Replies
Similar Messages:
Feb 11, 2014
I have a class TicketOrder. It's not recognizing my lstSectionNumber (Tickets.TicketForm.lastSectionNumber is inaccessible due to its protection level).
Here is the code for TicketOrder class:
public class TicketOrder
{
public TicketOrder(TicketForm form)
{
this.form = form;
}
//Declare static variables
[Code] .....
This is my code behind:
public partial class TicketForm : System.Web.UI.Page
{
//Declare variables
int myInt;
TicketUser user = new TicketUser();
TicketOrder order;
[Code] .....
View 3 Replies
Feb 21, 2011
Why doesn´t this property return a datetime formated with the following pattern when using the property in the codebehind page in my ASP.NET Webforms website? When debugging i can see that the value the returning datetime is "2011-02-21 16:13:29.670" wich is correct.
[code]....
And after assigning the returned property value to a hiddenfield in the .aspx page i get this value assign to the hiddenfield.value "2011-02-21 16:13:29"
hdnUserLastUpdated.Value = objUser.UserLastUpdated
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
Feb 2, 2010
I have a simple model that contains about 6 tables dealing with customers. As long as I am dealing with one table at a time or returning the single or list of an entire class everything is great. I am struggling with having to return subsets or combinations of the class information. For example customer sales by year.
This query involves these classes:
Customer
CustomerOrder
I need to return something like
CustomerName
Year
TotalSales
I can build the query fine. Returning that to a model is what puzzles me. I have no class that I form a generic.list with and nothing to inherit on the view. What is the best way to handle this?
View 4 Replies
Jul 8, 2010
I'm building an n-tier application, with the web client and the class library separate. I'm also using the factory pattern of development, using interfaces to act as containers for different objects they are associated with. The problem I'm expreriencing is that I declared a public interface class in the class library and I can create an instance of it in in my aspx pages but whenever I declare it in my custom control code-side, i get an error, like so:
Error 20 The type or namespace name 'IContentMaker' could not be found (are you missing a using directive or an assembly reference?)
notge that I have inherited the class library namespace using the 'using' keyword just in case you are wondering. My code is like so:
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TQO_Classes ; //importing the class library project
public partial class PageContentMgr : System.Web.UI.UserControl
{
private IContentMaker _data; //this line throws the error, it works fine on aspx pages
View 1 Replies
Apr 21, 2010
I have created my own custom role provider class "SGI_RoleProvider" and configured properly.
Everything is working fine.
Suppose that I have added a public method say "SayHello()", then how can i call that. Because if i am using Roles then the method is not displayed. If i am forcefully using that Roles.SayHello() then compiler gives the error.
how can i call this. Because creating a new instance of SGI_RoleProvider is meaningless.
View 1 Replies
Sep 19, 2010
I created a custom membership provider in my ASP.NET 4.0 web site, stored in App_Code, and referenced in my web.config.
However, it doesn't appear to be pulling values out of web.config during initialization.
The code was taken from [URL] , and the only modifications were changing "connectionStringName" here to the name of my connection string:
[Code]....
The connection string always comes back as nothing in this line:
[Code]....
No matter what I change the password format to in web.config, the default value here is always used:
[Code]....
So to me it's pretty clear it's not pulling out values for some reason. Here is the reference to the membership provider in web.config.
[Code]....
View 6 Replies
Feb 9, 2010
I have a composite control that returns a different control depending on a property value. The works however I can't seem to set the value of a textbox or the selected item in a dropdown list. Code does not produce error. What am i missing here??
[Code]....
View 4 Replies
May 17, 2010
I am creating custom server control. I have two classes in project. One is main class that render control and another will be used to render content based on condition.I just want to know how to render content from other classes in main class.For example. This isjust an example.My main class code
[Code]....
My TopLeftPane class
[Code]....
My page code on page load event
[Code]....
When I run the page, Header title always getting null. This is a just sample code. I will have more than 20 classes so I dont want to write a code in main class to render whole control.I hope all of you understand my problem.
View 3 Replies
Jul 18, 2010
We have a web project that contain its business methods in a class library project called "Bll.dll"
some methods of Bll.dll return List<> ... from a source - that i don't remember now - told that returning Collection<> is better than returning List<> Is it a valid ? Note that i don't make any process on values returned from BLL methods .. just view it in a web page
View 5 Replies
May 4, 2010
i have created a class with a sub, which removes a control from the original page...
for example, in the original page:
Code:
dim usertextbox as new textbox
usertextbox.id = "TEXTBOXIE"
form1.controls.add(usertextbox)
in the class:
Code:
public sub DeleteTextBox
dim pagetextbox as textbox
pagetextbox = page.findcontrol("TEXTBOXIE")
if not pagetextbox is nothing then
page.controls.remove(pagetextbox)
end if
end sub
the code in the class doesn't work..
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 3, 2010
I have Web Service in Asp.Net Application, i create a break point in Web service. In the web service i create a instance for custom class library and call a method inside the Class library. When i run the Application i can able to debug the Web service that i create the break point, but i want to debug that custom class library code also how to deug this.
When i try to debug by add custom class library inside the current solution, but am unable to debug that custom class library code.
View 2 Replies
Apr 1, 2010
I'm developing a website with ASP.NET MVC, NHibernate and Fluent NHibernate and want to know how can I customize my Map to get records using a custom Method.
My entities:
public class ImageGallery {
public virtual int Id { get; set; }
public virtual string Titulo { get; set; }
public virtual IList<Image> Images { get; set; }
ublic virtual bool IsActive { get; set; }
}
public class Image {
public virtual int Id { get; set; }
public virtual ImageGallery ImageGallery { get; set; }
public virtual string Low { get; set; }
public virtual bool IsActive { get; set; }
}
My Fluent NHibernate Maps:
public class ImageGalleryMap:ClassMap<ImageGallery> {
public ImageGalleryMap() {
Id(x => x.Id);
Map(x => x.Titulo);
HasMany(x => x.Images)
.KeyColumn("ImageGalleryID");
Map(x => x.IsActive);
}
}
public class ImageMap:ClassMap<Image> {
public ImageMap() {
Id(x => x.Id);
References(x => x.ImageGallery);
Map(x => x.Low);
Map(x => x.IsActive);
}
}
And, a method on my ImageRepository class:
public IList<Image> ListActive() {
return this.Session.CreateCriteria<Image>()
.Add(Restrictions.Eq("IsActive", true))
.List<Image>();
}
If I create an object this way:
ImageGallery ig = new ImageGallery();
I can access my the Image's list using:
foreach(Image img in ig.Images) {
...
}
However, ig.Images give me access to all images records and I would like to access just active records (or another criteria), using ListActive()'s repository methods.
View 1 Replies
Apr 22, 2010
I wanted to create a custom class that inherits from System.Exception and adds a few properties and methods specific to the project.
The issue I'm seeing is that a standard try/catch block catches generic Exception class and the compiler thinks that converting that to my custom class is OK. However, at runtime if the actual error is something else like a a System.Net.WebException for instance, then at runtime it will not convert to my custom class. Then my own error catch throws an InvalidCastException.
Obviously the one thing I don't want to happen is to have my error logging methods throw errors on their own...
So, how can I convert ANY exception to something that my custom class can use?
Here's a code example:
Csharp Code:
[code]....
Now, this code builds just fine... VS2008 and VS2010 have no issue with converting an "Exception" to "MyErrorClass", but at runtime it certainly doesn't like converting a "WebException" to "MyErrorClass"...
View 9 Replies
Mar 3, 2010
What I would like to have is a mapping between a custom file extension to a class that is not System.Web.UI.Page but a class of mine that inherits from System.Web.UI.Page.
i.e.:
*.aspx -> System.Web.UI.Page
*.my -> My.Package.MyClass (inherits from System.Web.UI.Page)
I know I can map any extension to be treated like .aspx but I can't find the way to do what I have in mind.
View 3 Replies
Jan 6, 2010
I have a method that returns an array of custom class objects that are created by parsing a text file. At the moment every time I use it I am rereading the file which isn't very efficient.
What I wat to do is create an array containing the objects when the page loads and store them in an array which can then be used later.
[Code]....
I thought I could create the static object using something like:
static Album myAlbums[] = readArray("Albums.txt");
but I am getting the following error:
A field initializer cannot reference the nonstatic field, method, or property 'B2M._Default.readArray(string)'
I am new to C# so this is probably something dumb. (Feel free to poke fun in my general direction if this is the case!)
View 2 Replies
Feb 16, 2010
What are the advantages of extending HtmlHelper instead of creating a Custom Class.
f.e. <%= Html.Table(data) %> vs <%= CustomClass.Table(data) %>
View 2 Replies
Jun 6, 2010
Is it possible to access a parent class from within an attribute.
For example I would like to create a DropDownListAttribute which can be applied to a property of a viewmodel class in MVC and then create a drop down list from an editor template. I am following a similar line as Kazi Manzur Rashid here.
He adds the collection of categories into viewdata and retrieves them using the key supplied to the attribute.
I would like to do something like the below,
public ExampleDropDownViewModel {
public IEnumerable<SelectListItem> Categories {get;set;}
[DropDownList("Categories")]
public int CategoryID { get;set; }
}
The attribute takes the name of the property containing the collection to bind to. I can't figure out how to access a property on the parent class of the attribute. Does anyone know how to do this?
View 2 Replies
Jan 20, 2010
I've create a custom attribute for my web pages... In the base page class I've created I'm trying to pull if that attribute has been set. Unfortunately it does not come back as part of the GetCustomAttributes function. Only if I explicitly use the typeof(myclass) to create the class. I have a feeling it's due to how asp.net classes are generated.
[Code]....
View 1 Replies
Sep 13, 2010
I have a custom class downloaded from internet. In this class, there is a properties where by the value can be either 0, 1 or 2 only and I MUST assign it during run-time. But some how, this assignment only work using VB, and not C#.
[Code]....
In C#, it the compiler said "missing cast or conversion...". But in VB, it works perfectly.
View 12 Replies
Jun 30, 2010
I wrote a custom RequestValidator implementation to deal with W.I.F. security tokens. Now I am trying to write a unit test for this class. This method is protected internal. Even using InternalsVisibleToAttribute, I am having no luck being able have my unit test compile against my implementation of:
bool
IsValidRequestString(HttpContext context,
string value, RequestValidationSource rvs,
string
collectionKey, out
int validationFailureIndex)
2. The HttpContext class used by this method is sealed so I am not sure how to mock one up with a mocking framework (i.e. rhinomocks in my case).
View 11 Replies
Oct 15, 2010
I'm using the default SqlMembershipProvider,but I've created a custom MembershipUser class (SoeMembershipUser) because I needed a "DisplayName" property.All the DisplayName does is look at the UserName and format it differently.When I try to cast a MembershipUser to a SoeMembershipUser user I get an InvalidCastException.
Exact error is:
"Unable to cast object of type 'System.Web.Security.MembershipUser' to type 'Soe.Tracker.SoeMembershipUser'."
Here is the code that fails:
SoeMembershipUser user = (SoeMembershipUser)Membership.GetUser(username); // invalid cast
I have also tried casting later like so:
MembershipUser user = Membershipship.GetUser(username); // ok
...
string displayName = ((SoeMembershipUser)user).DisplayName; // invalid cast
Here is the SoeMembershipUser class:
NOTE: I left off the constructors at first, but added them in later when I started having problems. Adding them made no difference.
public class SoeMembershipUser : MembershipUser
{
public SoeMembershipUser()
: base()
[code]...
View 2 Replies
Mar 27, 2011
I've got a custom class for the HTML Editor which adds specific buttons, however I can't figure out how to add specific font names and sizes to the FONTS and FONT SIZE boxes using the code below. I've figured out that simply adding the drop downs for the FONTS and FONT SIZES isn't enough. Once they're added, the specific have to be added.
YES, I have tried adding them using the FONTS and FONTSIZES properties in the HTML markup but after extensive research have determined that it can only be done via code.
[Code]....
View 2 Replies