473,327 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Can't get application obj to work in a code behind class

Hi there.

I am finally moving over to ASP.NET as the company I work for is
updating certain systems, ,so forgive me if this quesiton has been
answered before [I can't seem to find an answer].

I am using C# for this.

As a test I have built a class that sets up a wrapper around the
SmtpMail object so that with only a couple of statements an email can
be sent [this is just a test as this replicates what we will really be
doing with business objects].

So, to save on memory etc, I'd like to load this custom email class
into an Application object - something like

pmx.EmailSender Application["emailer"] = new EmailSender();

So it can be reused wherever in the application.

I'd then like in whatever .aspx file to be able to call the object as:

Application["emailer"].SendEmail (to, from, body);

And it will do it.

I've put the first bit of code into the global.asax file and it throws
an error:

Syntax error, bad array declarator. To declare a managed array the rank
specifier precedes the variable's identifier.

But I'm not sure what this means and if I am even approaching this the
write way.

Weirdly I seem to find loads of information saying you can store
Objects in the Application object but then everyone just uses the
example Application["varname"] = "some string"; - Not really the height
of complexity!

Any help or suggestions would be very greatly appreciated.
Cheers
AndrewF

Nov 19 '05 #1
4 1179
Type Variable[rank]. is to declare an array.

It should be just :

Application["emailer"]=new EmailSender();

As a side not you could just expose this as a class static member. You could
then use directly this class rather than storing an instance in an
application variable...

Patrice

--

"Andrew Fisher" <dr********@hotmail.com> a écrit dans le message de
news:11**********************@c13g2000cwb.googlegr oups.com...
Hi there.

I am finally moving over to ASP.NET as the company I work for is
updating certain systems, ,so forgive me if this quesiton has been
answered before [I can't seem to find an answer].

I am using C# for this.

As a test I have built a class that sets up a wrapper around the
SmtpMail object so that with only a couple of statements an email can
be sent [this is just a test as this replicates what we will really be
doing with business objects].

So, to save on memory etc, I'd like to load this custom email class
into an Application object - something like

pmx.EmailSender Application["emailer"] = new EmailSender();

So it can be reused wherever in the application.

I'd then like in whatever .aspx file to be able to call the object as:

Application["emailer"].SendEmail (to, from, body);

And it will do it.

I've put the first bit of code into the global.asax file and it throws
an error:

Syntax error, bad array declarator. To declare a managed array the rank
specifier precedes the variable's identifier.

But I'm not sure what this means and if I am even approaching this the
write way.

Weirdly I seem to find loads of information saying you can store
Objects in the Application object but then everyone just uses the
example Application["varname"] = "some string"; - Not really the height
of complexity!

Any help or suggestions would be very greatly appreciated.
Cheers
AndrewF

Nov 19 '05 #2
Thanks for your help Patrice however I've now created a different
problem.

I can declare this variable now okay and that isn't throwing an error,
but now when I go to use it in my page such as:

Application["emailer"].to = "em***@address.com";

It is now saying that: 'object' does not contain a definition for 'to'
- it is all spelt right etc so I know that there is a definition for
the propert "to" in this object.

Now I know what the compiler is telling me, and in your explanation
above I realise now that the Application object is just an array of
objects so I am dropping an object onto that array... but how do I now
use the properties and methods of my custom object.

I'd be quite happy if there is a better way of doing this as well so if
someone can enlighten me on this score I'd be very grateful.

AndrewF

Nov 19 '05 #3
You have now to "cast" the variable so that the compiler knows the expected
type.

As I said you could likely achieve the same result by creating a class with
static members (i.e. members that "belongs" to the class rahter than to an
instance). This way there is no need to store an instance then in
Application...

I suggest reading at least one time the whole C# spec :

http://msdn.microsoft.com/library/de...pSpecStart.asp
Patrice

--

"Andrew Fisher" <dr********@hotmail.com> a écrit dans le message de
news:11**********************@z14g2000cwz.googlegr oups.com...
Thanks for your help Patrice however I've now created a different
problem.

I can declare this variable now okay and that isn't throwing an error,
but now when I go to use it in my page such as:

Application["emailer"].to = "em***@address.com";

It is now saying that: 'object' does not contain a definition for 'to'
- it is all spelt right etc so I know that there is a definition for
the propert "to" in this object.

Now I know what the compiler is telling me, and in your explanation
above I realise now that the Application object is just an array of
objects so I am dropping an object onto that array... but how do I now
use the properties and methods of my custom object.

I'd be quite happy if there is a better way of doing this as well so if
someone can enlighten me on this score I'd be very grateful.

AndrewF

Nov 19 '05 #4
Andrew Fisher wrote:
Application["emailer"].to = "em***@address.com";
(abridged) Now I know what the compiler is telling me, and in your explanation above I realise now that the Application object is just an array of
objects so I am dropping an object onto that array...

The Application collection stores everything as System.Object, so you'll
have to do a type-cast to convert the EmailSender from System.Object to
EmailSender. The following examples use different techniques to do this:
// Do this:
((EmailSender)Application["emailer"]).to "em***@address.com";
// ..or this..
EmailSender mySender=(EmailSender) Application["emailer"];
mySender.to="em***@address.com";
// ..or this...
EmailSender mySender=Application["emailer"] as EmailSender;
mySender.to="em***@address.com";

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael Evanchik | last post by:
Tying not to spaghetti code which seems to be easy to do in .net, im trying to do my main .net html in index.aspx, use repeated .net html in an .ascx files and all code im doing in .vb code behind...
2
by: Jim Heavey | last post by:
I am tyring to figure out why a class that I am trying to instatiate can not be found. I am NOT WORKING WITH PRE_COMPILED code. I am dragging the source code over and placing the code in a...
9
by: tshad | last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't seem to get the Sub (writefile) to execute. It displays all the response.write lines that are called directly, but not...
6
by: Plamen Doykov | last post by:
Hi all I have converted a simple project from ASP.NET 1 to 2.0 with the latest prerelease of Visual Studio 2005. The problem is I can't access internal members from the code behind. It gives:...
3
by: daz_oldham | last post by:
Hi Everyone I'm going through the process of publishing my application to a testing server and I have been hit by a bit of a problem. Any pages where I am calling stored procs in my database...
6
by: David Colliver | last post by:
Hi, using vb.net 1.1 I am trying to add a control to a placeholder but am having problems with it. I do it practically the same way as i do in C# (I have more C# skill than VB.NET)and I...
4
by: Joseph Geretz | last post by:
We use a Soap Header to pass a token class (m_Token) back and forth with authenticated session information. Given the following implementation for our Logout method, I vastly prefer to simply code...
0
by: anileshlakhtakia | last post by:
Hi, I am getting this problem and i am not able to understand what is the logic behind this.My Problem is i have 2 user controls on my application having same namespace lets say...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.