C# - Access Parent Class From Custom Attribute?
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
Similar Messages:
May 24, 2010
I have a class (name PageBase) that is inhariting System .Web.UI .Page and all my .aspx page behind classes are inhariting this class. This way I have put some common things in PageBase class.
For showing errors I want to put showMessage funtion in PageBase as well so that I may have not put it in every page and it will easy to manage this way.
Probem is that how PageBase class will access a control which is in aspx page in its child class (child class of PageBase) .
I dont want to pass control as argument to function in parent class, is ther any other way ?
View 7 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
Jan 21, 2010
1) I've page class public partial class MyDelivery : System.Web.UI.Page
2) ASCX is in different subfolder public partial class MyControls_Hello_Bye : System.Web.UI.UserControl
I am unable to access #1 parent page class from control
View 2 Replies
Feb 25, 2010
Do i remove the ability to call a method from the class my page is inherited from?
I am trying to build my custom Role Provider and certain method i not want to be accessible.
View 2 Replies
Sep 19, 2015
I've got a class that create a report in a PDF - looks like this
Code:
Option Explicit On
Imports PdfSharp
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf
Imports System.Data.SqlClient
Public Class acsReportWriter
[Code] ...
And I access this class from within a web service call like this
Code:
Using acsRpt As New ACSReport.acsReportWriter
acsRpt.StartDocument(strViewName, strTitle, username)
Using dcn As New SqlConnection(connStr)
Using cmd As New SqlCommand
cmd.CommandType = CommandType.StoredProcedure
[Code] ....
So - in that web service I can access APPLICATION like this
Code:
With Application
.Lock()
' need to do work here
.UnLock()
End With
I need to be able to access APPLICATION from the acsReportWriter class to put status message every so often so another AJAX POST can fid out how many pages are done.
I'm having a hard time even adding IMPORTS to SYSTEM.WEB in the acsReportWriter class
View 1 Replies
May 24, 2010
I have a class UserControlBase that inherits System.Web.UI.UserControl and my user controls inherit UserControlBase class. UserControlBase has some common functions that are used in all user controls.
I want to put error display funtion to UserControlBase as well so that I may not have to declare and manage it in all user controls. Error will be displayed in some label in usercontrol. Issue is how to access label which is in usercontrol in UserControlBase in function ?
View 1 Replies
Jan 26, 2010
I have a custom control that I declare like:
<hello:someControl id="asdf" />
Now I need to access a config setting in the web.config's appsetting and give access to it to the control.
I want to pass this value using the attribute.
How can I do this?
View 1 Replies
Jan 13, 2010
I built a base controller class inherits from Controller class to add some custom behavior to all controllers which will inherit from this base class.
My issue is when I try to access HTTPContext and Session objects in my custom base class, they are always null.
Am I doing something wrong or need missing something?
My custom base class definition:
public class ApplicationControllerBase : Controller
controllers classes definition:
public class HomeController : ApplicationControllerBase
using ASP.NET MVC 1, .NET 3.5.
UPDATE:
It seems the issue is I try to access HTTPContext in the constructor while HTTPContext is not ready yet, I tried it in the OnActionExecuted event handler and it works fine.
My question is what is the best place to access Session object in my custom controller class, that will guarantee executing my code with all controllers.
View 3 Replies
Jul 20, 2010
I have an existing class for an input, is it possible to add an additional class for the object in C#.net, instead of doing a if/else and not having a preset class on the object in the first place?
View 3 Replies
Jul 6, 2010
I am going to have multiple "types" of an object and I am really not sure how best to retrieve/save those multiple types without having a separate save/retrieve for each type.
My classes:
[Code]....
I hope this makes sense. I'd rather not add a "type" column as I have this in another part of my database and I am not really liking it too much
UPDATE
Here's more info/questions for clarification, if necessary.
I'm really at a loss for how to incorporate them into my repository pattern.
When I call getEvaluation, I want it to return an abstract Evaluation, but I'm struggling with this code. Same with Saving - any insight on this would be excellent
UPDATE 2
Database:
Evaluations
Id (PK)
Comment
EvaluationType1
Id (FK to Evaluations.Id)
Field
EvaluationType1
Id (FK to Evaluations.Id)
Field
So, in getEvaluation(int id), I need to figure out what type of Evaluation they want. Does this mean I should pass in a type? Same is true in saveEvaluation, But I can do a switch/function map to see what Type it is.
View 6 Replies
Mar 15, 2011
recommend a data access class / helper class for Access databases, similar to the sqlhelper class found in the (Data Access Application Block)?
View 6 Replies
Nov 8, 2010
What is the class attribute and how to use
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
Jan 21, 2010
i use GUI tool of vs2008 to generate some LINQ to SQL class, my problem is StringTemplate can not reach attributes of those model
$persons:{
<li>$it.name$</li>
}$
it printed:
<li></li>
<li></li>
<li></li>
name is public property of Person model. If i create a person class by myself, and the same attributes, StringTemplate can get it.
View 2 Replies
Jul 26, 2010
I've been working on a rather large web application that requires a specific id param in the url for every page visited (for example, /controller/action/id?AccountId=23235325). This id has to be verified every time someone visits a page. want to reduce code replication as much as possible, and was wondering if there is a way to use an init method or constructor in a controller that inherits the MVC controller, and then have that controller extended by the others.
View 1 Replies
Feb 16, 2011
I have a VS 2003 Web app that I'm creating. I'm using a Panel control and I'm trying to apply a CSS class to this panel. However, when I try coding the following statement
<asp:Panel class="pnl2" runat="server">
it doesn't like the "class" attribute saying "could not find any attribute 'class' of element panel"? I'm used to using VS 2005 and higher and haven't seen this before. What am I doing wrong?
View 3 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
Jan 11, 2011
I have an interesting problem with a WCF Service I am creating. As background fodder my solultion uses MVC 3 RC2 as the web interface. I am developing the solution as an N-Tier application using the Entity Framework 4.0 with POCO Self Tracking Entities, repository and unit of work approach. I am using the STE's more as an advanced POCO since STE do not seem to play well as of yet in the real world as they were meant to and since they do seem to give me better interfacing with the DB through my layers still. Additionally, I am incorporating WCF into the solution as the backend for the models based on info I am reading and the fact that I will need to also access these services via a windows service app on the client computers.
So, I have a datastore which includes my edm and the repositories. The POCO STEs are generated in a separate layer in what I have called my Domain Models. Within my domain area I also have a Core app holding my utilities. I am currently incorporating an additional domain element as a WCF service using the RESTful template. This WCF will be servicing both my MVC controllers and a Windows Service app on the client computers.
Now, on to the problem: Within this solution I have an Entity Set of People (or Person?). Within that Entity set I have a chain of inherited entities as follows Person->User->StaffMember->Provider where Provider is the resultant child. Within my WCF I have a ProviderService, a StaffMemberService and a UserService. In each of these Services one of my OperationContracts is a Get(string id) amongst others. the Get(String id) contract is the one that is causing me problems. Within that Get(String id) contract I do the following for the User:
[Code]....
and for the Provider:
[Code]....
Now, what has gotten me completely confused is that the Provider one works like a charm. But if I use the UserService to call the User of the same Id (Since User is a base class for Provider, this should work) I get an error saying it was a bad service call. (The ProviderService, as stated works and returns all the correct data). When I debug it, the UserService Get(String id) function actually works as expected up to and through the return statement (ie the user variable actually contains all the proper data that I would expect on the call). It is only after the return that I get the web page giving me that error and points me to the help page for the service. (I am using the browser to view the results at this point only). </P><P>I am assuming it has something to do with serialization? But why is it displaying the derived class with all expected data, which yes does include the data not being displayed as a user data, I am calling the data using the same UserId. I am not expecting someone to inspect my code, but to be a traffic cop and point me in the direction I need to look.
View 12 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
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
Jun 14, 2010
I have a hyper link control and I set the NavigateURL and the ImageURL property at runtime. I also need to set the class of the image tag that it generates but I cannot figure out how I can do that. The solution mentioned here [URL] does not work because the image url is hard coded.
View 2 Replies
Nov 4, 2010
I have created a web service. When I check the service directly from it's web page it works correctly. Here's what the code looks like:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Configuration;
using System.Runtime.Serialization;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
using Microsoft.SharePoint;
using System.Collections;
namespace MDA.WebParts.SPRolodex_Web_Service
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService()]
public class SPRolodex_Web_Service : System.Web.Services.WebService
{
public SPRolodex_Web_Service()
{
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool ListExists(string personalUrl, string listName)
{
try
{
SPSite mySite = new SPSite(personalUrl);
SPWeb web = mySite.OpenWeb();
SPList list = web.Lists[listName];
return true;
}
catch (ArgumentException)
{
return false;
}
}
}
}
However, when I call the method using ServiceProxy.js (a jQuery based library) I get this error
"Only Web services with a [ScriptService] attribute on the class definition can be called from script."
As you can see the class has the ScriptService attribute and the methods have the ServiceMethod attribute.
View 1 Replies
Apr 7, 2010
I'm getting started with Astoria/ADO.NET Data Services/WCF Data Services. Looking through a lot of the code samples out there, it appears that the MimeType attribute used to be a method level attribute. After installing the latest update, it is now a class level attribute.
If I have more than one Service Operation that I want to return as a certain MimeType, then it appears now that I have to create a new service for each operation. Is this correct?
Most examples are like this:
[WebGet]
[SingleResult]
[MimeType("application/pdf")]
public IQueryable<byte[]> FooPDF()
{
var result = from p in this.CurrentDataSource.MyPDFs
where p.FooID == 2
select p;
return result.Take(1).Select(p => p.PDF);
}
I get "Attribute 'MimeType' is not valid on this declaration type. It is only valid on 'class' declarations." when I compile, because now I can't do this.
Now, I have to do this:
[MimeType("FooPDF", "application/pdf")]
public class FooService : DataService<FooDBEntities>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetServiceOperationAccessRule("FooPDF", ServiceOperationRights.All);
}
[WebGet]
[SingleResult]
public IQueryable<byte[]> FooPDF()
{
var result = from p in this.CurrentDataSource.MyPDFs
where p.FooID == 2
select p;
return result.Take(1).Select(p => p.PDF);
}
}
What's worse is that I can't add duplicate MimeType attributes to my class.
View 1 Replies
Jul 29, 2010
VS 2010 crashes instantly when I press = when adding the class attribute to anything.
The exact error I get is
Microsoft visual studio 2010 has stopped working.
Adding any other attribute works fine.
View 4 Replies