C# - Application Object Access From Regular Class?
Mar 25, 2011
store our DAO objects in the Application object, so there's one object of each available for the whole application.
This Application object is easily accessed in the Page codebehind itself, but how do we access it from a plain class that is not extending anything?
View 1 Replies
Similar Messages:
Jul 20, 2010
In a project I'm working on, the master page codebehind does a load of complex checks and confirmations that decide the navigation list displayed on the TreeView of the page. Now, I need a way to access this list from another front-end page, such as "frontpage.aspx".
This serves two purposes. One, the masterpage will hide pages on the navigation list the user shouldn't have access to, but the user can still enter the page by typing the page name into the URL manually. By being able to browse through the TreeView, I can isolate the whole authorization into a single method by simply checking if the page name exists within the currently used TreeView.
Two, this will allow me to easily change the displayed content of any page without checking the database or storing sessions for whatever specific rights the current user has, as I can just look if the TreeView contains "Products Admin" for example, and then use that to hide or display the section of the page that has to do with "Product Admin" functionality.
View 3 Replies
Jan 18, 2010
I have a page, Default.aspx, with its own code-behind file like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public int[] anArray;
}
What I'd like to do is access to "anArray" from a C# class (not tied to a page) declared in App_Code folder. What can I do?
Edit: As said in the first comment, I really apreciate your about refactoring my connection objects. However, what I'm really doing here is to rewrite an old PHP application in order to get comfortable with basic C# and ASP.NET, so this code will never go really live. So, I'm still intersted in a way (if any) to access an object declared in a code-behind code from a standard C# class.
Edit2: I removed the OdbcConnection object in order to focus to the real problem: how to refer to an object istantiated in a code-behind file from a C# class situated in App_Code?
View 4 Replies
Oct 29, 2010
I am implementing a custom membership and role providers where I need to store all the role/membership information in the user's session.
I am implementing these custom providers inside a class library project (different from the website project) and need to access the session in them. The idea is to store the role/membership related information in the session after retrieving them for the first time from the database.
When I try to access the Session using System.Web.HttpContext.Current.Session
I get this as a null object (Object reference not set to an instance of an object.
Why is the session turning out to be null?
View 1 Replies
Mar 16, 2011
I have a custom MembershipProvider that I'm using in an ASP.NET 2.0 application. Inside of the class that extends membership provider, I have a function called AttemptLogin() that sets session variables if the user is valid. Inside that function, are a number of session variable assignments similar to the following:
HttpContext.Current.Session["id"] = "12345";
AttemptLogin() is being called by the Application_BeginRequest function in global.asax. This code works fine when I open it in visual studio, and then run it in the built-in development server by clicking "Start Debugging". However, when I deploy it to our testing server (Windows 2003 Server 64-bit running IIS in 32-bit mode), execution breaks when it reaches the code above, giving me the following message:
[NullReferenceException: Object reference not set to an instance of an object.]
CustomMembershipProvider.AttemptLogin() in c:InetpubwwwrootJoshApp_CodeCustomMembershipProvider.cs:1097
ASP.global_asax.Application_BeginRequest(Object sender, EventArgs e) in c:InetpubwwwrootJoshGlobal.asax:14
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
How can I access the session state successfully in this situation? Why does it work locally and not on the server?
View 2 Replies
Mar 28, 2010
I'm having a problem with a class library I'm building. I have a class called Users and inside this class I have a property called UserInfo that is an object. Both of the classes Users and UserInfo are built using MyGenerations dOOdads. When I create an object instance of the Users class I am able to access the UserInfo property without a problem in my Windows App, however when I using the same library in a website the UserInfo property continues to return a no reference error. Like I said when running it in a WinApp I have no problems at all, I can access the UserInfo property and likewise all of UserInfo's properties. I am also having problems trying to debug the library using the website. And again I have no problems when using the WinApp. The way I've set it up is I have the Class library project open, and then I add the WinApp project and then the website project. When I set the WinApp as the startup project and run it I have no problems, I can set breakpoints and step through the code no problem. But when I set the Website as the startup project and try to debug I get a massage saying the breakpoint won't be hit. I then do what it tells me and right click on the breakpoint and set the location to allow the source to be different. This lets me hit the breakpoint, but every time I hit F10 to step I get "There is no source code available for the current location." For every step I take. This is making it really hard for me to figure out what going on with the code in the website. Sorry for the lengthy explanation. Here's the Users class, again it works great in the WinApp, just not the website.
[Code]....
View 6 Replies
May 27, 2012
I am trying to develop logic to add dynamic controls to page via class method. So I want to know how can we access the ASP.Net Page object reference in class method.
View 1 Replies
Feb 28, 2011
I have two projects in one solution :
Class Library for my BLL and DAL classes Web Application for my PL
Now I just use the keyword "using" in the BLL and DAL classes and get access to their methods easily. but now I try to reference the BLL and DAL in the web application project through the "using" keyword but it won't let me (the name space couldn't be found (are you missing reference ?)) .. then I tried to reference the library's dll (grabbed it from the ClassLibrary/bin/debug) and the same error just popped out again!
Summery:
My solution consists of two projects (ClassLibrary and a WebApplication) and I want to use/reference the classes/dlls of the class library in the web application
View 3 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
Aug 7, 2010
How do I store a variable or object application wide in ASP.net MVC. In regular ASP, you had the Application object, and in ASP.net too apparently.
View 1 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
Aug 30, 2010
I've scenario where I want to insert data into database without post back. there are around 12 to 13 fields which i need to insert. I'm passing DTO from the client side which is actually Json object. Now the problem which i'm facing is how to convert that Json object which i got in webservice to the "class" (in my case class name is User) object.
[Code]....
In the above case AddNewUser method takes the object of User class. But i'm getting casting error. So how do I convert Json object to the "User" class object?
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
Aug 10, 2012
Code to read the span having the particular class name and assign to match collection.
I am having a set of html tags.
<span><a href="asb.aspx">Dummy</a></span>
<span class="active"><a href="abc.aspx">Hi thi is titile</a></span>
I need to get the span having the class name ="active".That is i need the result
<span class="active"><a href="abc.aspx">Hi thi is titile</a></span>
It will be fine if i get the text in the a tag that is with in the span having the class name "active".
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
Jan 6, 2010
I have a regular method I want to call. I need to use properties of the GridViewRowEventArgs Class within this method.
i.e.
[Code]....
Of course the above code is not valid because I don't think you can put GridViewRowEventArgs within the method like that. I don't want to put it within a event handler because that even handler is doing other things. I want to be able to call this seperatley.
View 2 Replies
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
Jul 2, 2010
I tried to get the heade row text with the following code, but it failed.
[Code]....
Error returned was "Object reference not set to an instance of an object." on this line:
[Code]....
View 3 Replies
Feb 17, 2010
On DBML I have two entities as Parent, Child. I am trying to assign Child class properites in a Parent.
[code]....
I am getting the following Error:
Cannot access a disposed object.
Object name: 'DataContext accessed after Dispose.'.
View 2 Replies
Aug 13, 2010
I have developed a website that allows users to upload office documents then uses the office object model to convert the document to an HTML file that it then displays in an iFrame. I have, of course, included references to Office.interop.word, and the site works fine on my development machine. When I uploaded it to my production server the site functions fine until I try to upload a document. I initially got a similar error that said "COM object not registered". I realized that Word wasn't installed on my production server. So I installed word and now when the server tries to access the word object model I receive the following error:
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
I searched the registry for the corresponding CLSID and found a corresponding folder. I added full control to the IUSR_ account and due to the persistence of the error I eventually added full control to "everyone" and ensured these permissions inherited down to the rest of the folder. I then added full control to IUSR_ and again eventually added full control to "everyone" to my microsoft office folder. I don't know what other permissions to grant and where in order to make this "Access is denied" error go away. I must be granting them in the wrong place, because as far as I know I can't be any more permissive than "Everyone" "Full Control".
View 1 Replies
Jan 30, 2011
Actually i want to cast the type from find control to div but i cant find the class with div or body or form name why so?
View 5 Replies
Jan 16, 2010
why I get this error:
Object reference not set to an instance of an object.
when I try to access a LinkButton inside a Repeater as follows:
[Code]....
[Code]....
View 4 Replies
Sep 15, 2010
Suppose we declare and define the variable in one class let say FirstClass and we want to use that variable in another class let say SecondClass which is outside of FirstClass .how to do this?
View 2 Replies
Nov 15, 2010
Is there any way to list all the class in my ASP.Net application(Including class in App_Code and Partial Class(aspx pages and asmx user controls)
View 3 Replies
Jul 17, 2010
I am trying to run the 15 minutes movies MVC application but I got the following error:
Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
[Code]....
View 1 Replies