What Is A Generic Class Declaration
May 11, 2010What is a Generic Class Declaration? and when should it be used?
View 2 RepliesWhat is a Generic Class Declaration? and when should it be used?
View 2 RepliesI have a user control in which I have declared a connection string as a private class variable.
I have a bunch of cascading dropdown lists in this control.
In one of my subroutines PopulateDdlPostalCodes I get an error "Connection was not initialized".
In all the other subs that use Conn, the class variable is being recognized.
If I duplicate the declaration of Conn in this sub then all works ok.
Why is this sub different than all the others?
[Code]....
public class NHibernateSessionPerRequest<T>:IHttpModule
{
public void Dispose() { }
public void Init(HttpApplication context)
{
context.BeginRequest += BeginRequest;
context.EndRequest += EndRequest;
}
}
How can it be registered in web.config?
What am I missing here?I get the error Declaration Expected @ myPostData=
[Code]....
Dim encoding As New ASCIIEncoding()
Dim RateXML
As
String =
"123"
'Format the Data
Dim myPostData
As
Byte()
myPostData = encoding.GetBytes(RateXML)
^^^^^^^
ASP.net C# 3.5 Framework, working in Visual Studio 2008 currently.
What I want is a Generic Data Access Class. I have seen several of them but what I want is to see one that I pass the Connection String and the SQL statement and it will return a List of Objects or when only one item an Object or when no response needed a boolean to let me know if it succeeded?
How can I create generic class from System.Web.Mvc.ViewPage?
View 1 RepliesI have several custom classes that derive from a common base class so they share several members in common. I would like to be able to pass objecs from any of these three classes to a function that will "look at" common properties. However, it seems there is a catch 22 -- When I try to access a member (.FirstName) of the passed object, the computer reports an error that it thinks the member doesn't exist.
It seems to be a sort of contradiction -- since I didn't declare the type, the computer can't confirm existence, but it seems that it should have to take it on faith since the generic character of the type is specified by the code. Possibly there is something I don't know about that would fix this. I'm showing VB code for what I have so far. I went ahead and hardcoded an instance to confirm that the object exists and has the needed property. I commented out the line that had the code that resulted in the computer reporting an error.
[Code]....
I want to bind grid using Bindlist(Generic class) and also ensure it does not have an impact on performance of the page.
View 2 RepliesI 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.
If I have something like:
lbl1.Text = "lbl7.Text = "Blah blah text <A href="long URL">here</a>.""
Then it comes up with an error. I tried escaping the quotes but still doesn't work so what do I do?
I'm trying to create a control out of a class I found, and one of the overridden functions is the following:
protected override void PerformDataBinding(IEnumerable data)
However, when I try to build the control I'm getting the error as shown in the subject. I've tried searching, and it seems the signature for the original function matches the one I have, and all other solutions I've seen uses the same signature.
What is the difference between generic and non-generic collection?
View 1 RepliesI am working on a existing web application which I load from a folder. I mean application semms it is not created as website application from visual studio.
The controls defined in aspx are not having member declarations in .aspx.cs file and no designer.cs files were created. I mean nowhere controls are defined, but simply the controls defined in aspx are accessble in corresponding aspx.cs file wich same id of the control tag. those are being reconized even in intelligense.
How is it possible? is there any special configuration needed to make aspx controls declared automatically for aspx.cs file use.
How do I allow nullable string to my declaration?
I get this error "Type 'String' must be a value type or a type argument constrained to 'Structure' in order to be used with 'Nullable' or nullable modifier '?'." [:(]
Function Index(ByVal product As Product, ByVal category_1 As Nullable(Of String), ByVal category_2 As
Nullable(Of String)) As ActionResult
...
End Function
I have added one div in aspx page and i want to take the Id of that div in code behind file by usingĀ webcontrol.
View 1 RepliesI get a message - "Function without an 'As' clause" for HMAC_MD5 and "Variable declaration without an 'As' clause" for Key and Value. But the code works. But the messages still exists. Is there a way to fix this to avoid the messages?
[Code]....
I have an XSLT transform I am using to process an XML file, inserting it into the body of my aspx page.Reference the following for background information:
background on xml/xslt
I have the following in my xml file:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" [code].....
In the following page what is Container? There was no declaration of Container in anywhere in the page. How and why is it used?
[code]...
I know that this topic has already discussed a lot. But, what I face today is some more strange;
My environment is, Win 7, Visual Studio 2008, ie8
I created a sample aspx and added a gridview, could make it work nicely using below style;
thead tr
{
position: relative;
top: expression(this.offsetParent.scrollTop);
}
only when I comment out automatically generated DOCTYPE declaration;How can I make this webform work correctly with DOCTYPE declaration is on?
If a server control was declared like this
<my:customControl id="cc1" runat="server">
</my:customControl>
is it possible to access the text between the tags?
I have info from a couple of different tables that I need to be able to double click on a cell in a gridview and navigate to a couple of separate .aspx pages. Yesterday I learned how to use RowDataBound to get the name from a cell on a gridview to use in a delete confirmation dialoge box, and so am pretty sure I should be using this same RowDataBound, but I cant quite figure out where to start.
For example from the gridview below, I need to be able to double click in the "LoginIssue" field and navigate to an "EditLogin.aspx" page and subsequently be able to double click in the "ContractPath" and be able to navigate to a "ContractPath.aspx" page...or popup.
[Code]....
I have two repeaters bound to object collections. They both work fine. But when I move repeater B to repeater A's FooterTemplate the serverside declaration of repeater B disappear.This is not a parent/child relation.
Update:<asp:Repeater ID="myOuterRepeater" runat="server">
<ItemTemplate>
...
[code]...
I have the following custom model binder attribute:
[Code]....
However, when I use it as follows:
[Code]....
I get the following error:
Attribute 'MyApp.DateTime' is not valid on this declaration type. It is only valid on 'class, struct, enum, interface, param' declarations.
What am I missing?
Consider this code:
Partial Public Class MyAspNETClass
Inherits System.Web.UI.Page
Protected Shared MyVariable As String
Is Myvariable a variable used local for each instance of the page ? Or that variable is "shared" for all users accessing my page? Is MyVariable saved in server memory, or is it saved on the viewstate of aspx page?
I am able to access the controls of ".aspx" file in ".aspx.cs" directly without any declaration in ".aspx.cs" or in designer.cs. How is this possible? This is happeing only if I open website as using File System.
Create a new ASP.NET web site application with Visual Studio 2008. So following three files will be created automatically
[code]...
How btnSave is being recognized by .cs file without defining it anywhere as an object of System.Web.UI.WebControls.Button?