Showing posts with label object. Show all posts
Showing posts with label object. Show all posts

Saturday, March 31, 2012

The asp:LoginStatus

I can display the login status using the <asp:LoginStatus> tag.

Unfortunatelly, the object LoginStatus seems not to provide an attribute to
test it.

How can you read from the code (VB script) the login status?Progman
if page.user.identity.isauthenticated then
... user is logged in
else
... user is not logged in
endif

Good Luck
DWS

"Progman" wrote:

> I can display the login status using the <asp:LoginStatus> tag.
> Unfortunatelly, the object LoginStatus seems not to provide an attribute to
> test it.
> How can you read from the code (VB script) the login status?
>

The asp:LoginStatus

I can display the login status using the <asp:LoginStatus> tag.
Unfortunatelly, the object LoginStatus seems not to provide an attribute to
test it.
How can you read from the code (VB script) the login status?Progman
if page.user.identity.isauthenticated then
... user is logged in
else
... user is not logged in
endif
Good Luck
DWS
"Progman" wrote:

> I can display the login status using the <asp:LoginStatus> tag.
> Unfortunatelly, the object LoginStatus seems not to provide an attribute t
o
> test it.
> How can you read from the code (VB script) the login status?
>
>

The Basics

Hi,

I am very new to ASP. I am trying to make a secure site and I have some general questions.

Does the HttpSessionState object exist in the client's browser oron the IIS server? I assume that it must exist on the server or else itwouldn't really be any different than a cookie. Is this correct?In what order do events occur on the server when an HTTP requestis made. I am assuming that the request is made, the server gets theclients cookies, the server checks the web.config file, then the serverexecutes any necessary scripts and returns a webpage. Is this correct?Is there a nice tutorial about modifying the web.config file? Forexample, a tutorial which teaches people which XML tags do what in it?
Thanks a lot,

P10001.Session is on the server
2. there are a few more steps than that - search on asp.net lifecycle - though .Net isn't a script technolgy - morecorrect to say server creates objects- performs sub and functions - then renders html page
3.http://www.sitepoint.com/article/web-config-file-demystified
Thanks a lot.
Okay, the lifecycle does give me a lot of information that I am lookingfor, but it doesn't really mention (at least the pages which I readdidn't mention) when web.config is accessed in order to determineauthenication info etc. So I am still missing some important steps inthe lifecycle of a request.

The web.config link was also very helpful but I still don't know when the server uses it.

The best place

Hi,

where is the best place for setting components on load but only if
this is not a postback?

protected void Page_Load(object sender, EventArgs e) {
if(!Page.IsPostBack) {
//here?
}
}

Regards,
Etam.On May 27, 8:42 pm, etam <odwrot...@dotnet.itags.org.gmail.comwrote:

Quote:

Originally Posted by

Hi,
>
where is the best place for setting components on load but only if
this is not a postback?
>
protected void Page_Load(object sender, EventArgs e) {
if(!Page.IsPostBack) {
//here?
}
}
>
Regards,
Etam.


yup :-)
That's not a terrible place, although the Page_Init event might be better
depending on exactly what it is you're trying to do.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"etam" <odwrotnie@dotnet.itags.org.gmail.comwrote in message
news:1180291329.036276.205340@dotnet.itags.org.m36g2000hse.googlegr oups.com...

Quote:

Originally Posted by

Hi,
>
where is the best place for setting components on load but only if
this is not a postback?
>
protected void Page_Load(object sender, EventArgs e) {
if(!Page.IsPostBack) {
//here?
}
}
>
Regards,
Etam.
>

The best place

Hi,
where is the best place for setting components on load but only if
this is not a postback?
protected void Page_Load(object sender, EventArgs e) {
if(!Page.IsPostBack) {
//here?
}
}
Regards,
Etam.On May 27, 8:42 pm, etam <odwrot...@dotnet.itags.org.gmail.com> wrote:
> Hi,
> where is the best place for setting components on load but only if
> this is not a postback?
> protected void Page_Load(object sender, EventArgs e) {
> if(!Page.IsPostBack) {
> //here?
> }
> }
> Regards,
> Etam.
yup :-)
That's not a terrible place, although the Page_Init event might be better
depending on exactly what it is you're trying to do.
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"etam" <odwrotnie@dotnet.itags.org.gmail.com> wrote in message
news:1180291329.036276.205340@dotnet.itags.org.m36g2000hse.googlegroups.com...
> Hi,
> where is the best place for setting components on load but only if
> this is not a postback?
> protected void Page_Load(object sender, EventArgs e) {
> if(!Page.IsPostBack) {
> //here?
> }
> }
> Regards,
> Etam.
>

Wednesday, March 28, 2012

the best way to have some information accessable to all pages?

hello all,
I need to have access to some details in all my pages eg a Person object.
what is the best way to do it?
store in session object? or pass them through the QueryString or Application
variables etc?
what is the best and efficient way?It really depends on the nature of the application. Overall, I am not fond o
f
putting everything in hidden tags so it can travel on the Query String. It
potentially opens security holes.
Where you store information depends on the nature of the information.
If it is linked to the user, cookies are an option. For security, you can
send the user's token instead, or link it to the session ID. This will
require grabbing the information with each return, but it is safer than
storing in the cookie.
For session specific information, you can use the Session object as a cache.
You can also use the cache manager functionality of ASP.NET.
For page specific information (like the Person object is the person being
worked on, not the person using the app), you can use ViewState.
As I stated at the beginning, it really depends on the nature of the
application.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Annie" wrote:

> hello all,
> I need to have access to some details in all my pages eg a Person object.
> what is the best way to do it?
> store in session object? or pass them through the QueryString or Applicati
on
> variables etc?
> what is the best and efficient way?
>
>

the best way to have some information accessable to all pages?

hello all,

I need to have access to some details in all my pages eg a Person object.

what is the best way to do it?
store in session object? or pass them through the QueryString or Application
variables etc?

what is the best and efficient way?It really depends on the nature of the application. Overall, I am not fond of
putting everything in hidden tags so it can travel on the Query String. It
potentially opens security holes.

Where you store information depends on the nature of the information.

If it is linked to the user, cookies are an option. For security, you can
send the user's token instead, or link it to the session ID. This will
require grabbing the information with each return, but it is safer than
storing in the cookie.

For session specific information, you can use the Session object as a cache.
You can also use the cache manager functionality of ASP.NET.

For page specific information (like the Person object is the person being
worked on, not the person using the app), you can use ViewState.

As I stated at the beginning, it really depends on the nature of the
application.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Annie" wrote:

> hello all,
> I need to have access to some details in all my pages eg a Person object.
> what is the best way to do it?
> store in session object? or pass them through the QueryString or Application
> variables etc?
> what is the best and efficient way?
>

The Cache object

Hello!

Is there a way to get to the Cache object in some other way than the
current contex?
I mean - the Cache is independant from the request so I would expect to
see some kind of Cache.Current property or something like
HttpContext.Current, but unfortunately I've been unable to find one.
When it could be usefull is for example a situation when I put some
task to be done every few minutes on the server - independent from the
requests comming in.
The way I do it now is to catch one of the Requests, get the Cache from
there and store the reference to it in some global/static variable.

--
MichalHttpRuntime.Cache

You might need to reference the System.Web assembly, but you can use it for
any type of application, including windows forms, console, web service...

Karl

--
http://www.openmymind.net/

"Mikeon" <mikeon@dotnet.itags.org.icpnet.pl> wrote in message
news:1142928776.985959.270680@dotnet.itags.org.u72g2000cwu.googlegr oups.com...
> Hello!
> Is there a way to get to the Cache object in some other way than the
> current contex?
> I mean - the Cache is independant from the request so I would expect to
> see some kind of Cache.Current property or something like
> HttpContext.Current, but unfortunately I've been unable to find one.
> When it could be usefull is for example a situation when I put some
> task to be done every few minutes on the server - independent from the
> requests comming in.
> The way I do it now is to catch one of the Requests, get the Cache from
> there and store the reference to it in some global/static variable.
> --
> Michal
Hello!

Yep, I'm already referencing it, but! What I need is a way to get the
Cache object without the Context object which is only available during
request processing which is not allways the case when some code on the
server runs as in my example with tasks running on the server every few
minutes. The importatnt part is that the tasks are run even if no one
uses my application i.e.: no one is requesting pages at the moment and
there is some Timer object stored in the Application state which fires
some tasks.

--
Michal
Not sure if you read what I said, but you can use the HttpRuntime.Cache
which IS available even without a context..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/

"Mikeon" <mikeon@dotnet.itags.org.icpnet.pl> wrote in message
news:1142945004.761815.70410@dotnet.itags.org.z34g2000cwc.googlegro ups.com...
> Hello!
> Yep, I'm already referencing it, but! What I need is a way to get the
> Cache object without the Context object which is only available during
> request processing which is not allways the case when some code on the
> server runs as in my example with tasks running on the server every few
> minutes. The importatnt part is that the tasks are run even if no one
> uses my application i.e.: no one is requesting pages at the moment and
> there is some Timer object stored in the Application state which fires
> some tasks.
> --
> Michal
Thus wrote Mikeon,

> Hello!
> Is there a way to get to the Cache object in some other way than the
> current contex?
> I mean - the Cache is independant from the request so I would expect
> to
> see some kind of Cache.Current property or something like
> HttpContext.Current, but unfortunately I've been unable to find one.
> When it could be usefull is for example a situation when I put some
> task to be done every few minutes on the server - independent from the
> requests comming in.
> The way I do it now is to catch one of the Requests, get the Cache
> from
> there and store the reference to it in some global/static variable.

You can also consider using the Caching Application Block in EL 2.0. The
API is similar to ASP.NET's Cache class.

Cheers,
--
Joerg Jooss
news-reply@dotnet.itags.org.joergjooss.de
Hello!

Oh! I've missed this first line of yours. Of course it is what I was
looking for.
Thank you!

--
Michal

The Cache object...

I need to get some clarification on how this object is being implemented:

1. Global to the entire application (single server) -- is this on a per user session? Meaning Cache for user session A will be different from Cache for user session B?
2. What could cause the Cache values to be unreliable aka -- not available or cleared out (prior to expiration time)?

Thanks, Rob.

Hi,

Cache is global to entire application. It is one and the same for all users e.g shared for all users. Session is the user-specific data storage on the server.

Cache values can be cleared under memory pressure (priority depends on if one is explicitly given when cache item is added), and when AppDomain restarts: application pool restarts, web.config change, multiple file operations, maximum number of recompiles etc etc

Therefore you should check cache item for null reference before trying to access it. Steve Smith ahs written excellent article about ASP.NET caching (it's old but still valid):http://msdn2.microsoft.com/en-us/library/aa478965.aspx


Thank you for the response.

So if I were to add something like TextBox.ClientID (as the key) to the Cache, it would be possible for another user session to overwrite or get that same Cache item if they used the same TextBox.ClientID?

Rob.


Yes because it it is essentially one and the same storage for all users.

The Cache object

Hello!
Is there a way to get to the Cache object in some other way than the
current contex?
I mean - the Cache is independant from the request so I would expect to
see some kind of Cache.Current property or something like
HttpContext.Current, but unfortunately I've been unable to find one.
When it could be usefull is for example a situation when I put some
task to be done every few minutes on the server - independent from the
requests comming in.
The way I do it now is to catch one of the Requests, get the Cache from
there and store the reference to it in some global/static variable.
MichalHttpRuntime.Cache
You might need to reference the System.Web assembly, but you can use it for
any type of application, including windows forms, console, web service...
Karl
http://www.openmymind.net/
"Mikeon" <mikeon@dotnet.itags.org.icpnet.pl> wrote in message
news:1142928776.985959.270680@dotnet.itags.org.u72g2000cwu.googlegroups.com...
> Hello!
> Is there a way to get to the Cache object in some other way than the
> current contex?
> I mean - the Cache is independant from the request so I would expect to
> see some kind of Cache.Current property or something like
> HttpContext.Current, but unfortunately I've been unable to find one.
> When it could be usefull is for example a situation when I put some
> task to be done every few minutes on the server - independent from the
> requests comming in.
> The way I do it now is to catch one of the Requests, get the Cache from
> there and store the reference to it in some global/static variable.
> --
> Michal
>
Hello!
Yep, I'm already referencing it, but! What I need is a way to get the
Cache object without the Context object which is only available during
request processing which is not allways the case when some code on the
server runs as in my example with tasks running on the server every few
minutes. The importatnt part is that the tasks are run even if no one
uses my application i.e.: no one is requesting pages at the moment and
there is some Timer object stored in the Application state which fires
some tasks.
Michal
Not sure if you read what I said, but you can use the HttpRuntime.Cache
which IS available even without a context..
Karl
http://www.openmymind.net/
http://www.fuelindustries.com/
"Mikeon" <mikeon@dotnet.itags.org.icpnet.pl> wrote in message
news:1142945004.761815.70410@dotnet.itags.org.z34g2000cwc.googlegroups.com...
> Hello!
> Yep, I'm already referencing it, but! What I need is a way to get the
> Cache object without the Context object which is only available during
> request processing which is not allways the case when some code on the
> server runs as in my example with tasks running on the server every few
> minutes. The importatnt part is that the tasks are run even if no one
> uses my application i.e.: no one is requesting pages at the moment and
> there is some Timer object stored in the Application state which fires
> some tasks.
> --
> Michal
>
Thus wrote Mikeon,

> Hello!
> Is there a way to get to the Cache object in some other way than the
> current contex?
> I mean - the Cache is independant from the request so I would expect
> to
> see some kind of Cache.Current property or something like
> HttpContext.Current, but unfortunately I've been unable to find one.
> When it could be usefull is for example a situation when I put some
> task to be done every few minutes on the server - independent from the
> requests comming in.
> The way I do it now is to catch one of the Requests, get the Cache
> from
> there and store the reference to it in some global/static variable.
You can also consider using the Caching Application Block in EL 2.0. The
API is similar to ASP.NET's Cache class.
Cheers,
--
Joerg Jooss
news-reply@dotnet.itags.org.joergjooss.de
Hello!
Oh! I've missed this first line of yours. Of course it is what I was
looking for.
Thank you!
Michal

Monday, March 26, 2012

The connection is already Open (state=Open, Fetching).

Hello again.

This problem relates to a Business Object that I've created. I get the above error when I try t call a Sub within the business object that inserts into the database. I have various other Subs and Functions that Select from the database and they don't seem to have a problem. I can't see where the connection is being left open... But I've been staring at this all day now so theres a good chance I'm missing something obvious...

The VB for the business object is below. The sub in the aspx page that calls it is:

Sub Button1_Click(Source As Object, E As EventArgs)
dim objForum as New BidwellsDevelopments.PublicForum
objForum.ReplyToForum(pubThreadID, pubUser,oEdit1.Content)
End Sub

And the business object code (the sub in question is at the bottom in bold):

' VB Document
Imports System
Imports System.Data
Imports System.Data.OleDb

Namespace BidwellsDevelopments

Public Class DevelopmentDetails
public DevelopmentID as Integer
public Name' as string
public Description' as string
public Keywords' as string
'public Live' as integer
public Logo' as string
public MainImage' as string
public HomePage' as string
public PostCode' as string
public Address1' as string
public Address2'' as string
public Address3' as string
public Town' as string
public County' as string
public Country' as string
'' public ClientID' as integer
' public ManagerID' as integer
' public CreatorID' as integer
End Class

Public Class Development
Private objConn as new OleDbConnection (System.Configuration.ConfigurationSettings.AppSettings("ConnectionString"))

public function GetDevelopment(developmentID) as DevelopmentDetails


Dim objCmd As New OleDbCommand("spGetDevelopment", objConn)
objCmd.CommandType = CommandType.StoredProcedure

Dim objParam As New OleDbParameter("@dotnet.itags.org.DevelopmentID", OleDbType.Char)
objParam.Value = developmentID
objCmd.Parameters.Add(objParam)
Dim objReader as OleDbDataReader

try
objConn.Open()
objReader = objCmd.ExecuteReader
catch ex as OleDbException
throw ex
end try
dim objDetails as new DevelopmentDetails

while objReader.Read()
objDetails.DevelopmentID = developmentID
objDetails.Name = objReader(1)
objDetails.Description = objReader(2)
objDetails.Keywords = objReader(3)
'objDetails.Live = objReader.GetInt32(4)
objDetails.Logo = objReader(5)
objDetails.MainImage = objReader(6)
objDetails.HomePage = objReader(7)
objDetails.PostCode = objReader(8)
objDetails.Address1 = objReader(9)
objDetails.Address2 = objReader(10)
objDetails.Address3 = objReader(11)
objDetails.Town = objReader(12)
objDetails.County = objReader(13)
objDetails.Country = objReader(14)
'objDetails.ClientID = objReader.GetString(15)
'objDetails.ManagerID = objReader.GetString(16)
'objDetails.CreatorID = objReader.GetString(17)
end while
objReader.Close

return objDetails
End function

End Class

Public Class PublicForum
Private objConn as new OleDbConnection (System.Configuration.ConfigurationSettings.AppSettings("ConnectionString"))


Public function DisplayForum(developmentID) As OleDbDataReader

Dim objCmd As New OleDbCommand("spDisplayPFTopics", objConn)
objCmd.CommandType = CommandType.StoredProcedure

Dim objParam As New OleDbParameter("@dotnet.itags.org.DevelopmentID", OleDbType.Char)
objParam.Value = developmentID
objCmd.Parameters.Add(objParam)
Dim objReader as OleDbDataReader

try
'objCmd.Connection.Open()
objConn.Open()
return objCmd.ExecuteReader
catch ex as OleDbException
throw ex
end try
End Function

Public function DisplayThreads(topicID) As OleDbDataReader
Dim objCmd As New OleDbCommand("spDisplayPFThreads", objConn)
objCmd.CommandType = CommandType.StoredProcedure

Dim objParam As New OleDbParameter("@dotnet.itags.org.TopicID", OleDbType.Char)
objParam.Value = topicID
objCmd.Parameters.Add(objParam)
Dim objReader as OleDbDataReader

try
objConn.Open()
return objCmd.ExecuteReader
catch ex as OleDbException
throw ex
end try
End Function

Public function DisplayMessages(threadID) As OleDbDataReader
Dim objCmd As New OleDbCommand("spDisplayPFEntries", objConn)
objCmd.CommandType = CommandType.StoredProcedure

Dim objParam As New OleDbParameter("@dotnet.itags.org.ThreadID", OleDbType.Char)
objParam.Value = threadID
objCmd.Parameters.Add(objParam)
Dim objReader as OleDbDataReader

try
objConn.Open()
return objCmd.ExecuteReader
catch ex as OleDbException
throw ex
end try
End Function

Sub ReplyToForum (threadID, creatorID, entry)
Dim objCmd As New OleDbCommand("spAddPFEntry", objConn)
objCmd.CommandType = CommandType.StoredProcedure

Dim objParam As New OleDbParameter("@dotnet.itags.org.ThreadID", OleDbType.Char)
objParam.Value = threadID
objCmd.Parameters.Add(objParam)

objParam = New OleDbParameter("@dotnet.itags.org.CreatorID", OleDbType.Char)
objParam.Value = creatorID
objCmd.Parameters.Add(objParam)

objParam = New OleDbParameter("@dotnet.itags.org.Entry", OleDbType.Char)
objParam.Value = entry
objCmd.Parameters.Add(objParam)

try
objConn.Open()
objCmd.ExecuteNonQuery
objConn.Close()
catch ex as OleDbException
throw ex
end try
End Sub


End Class
End Namespace

Any hints greatly received!

Thank you for your time

Shaun

Wow.. I don't think the problem lies within the code that you have bolded but within all the functions that return DataReader objects. You're going to have to pass them as:
return objDataReader(CommandBehavior.CloseConnection)
and then in your main code that is actually calling the function and expecting a reader in return you must do:
dim dr as SqlDataReader
dr = Class.MethodReturnsDatareader
dr.close()
Also, you may want to add Finally blocks to all those Try blocks and explicitly close the connection there. Because if any of those methods error out, the connection is still open...

Thanks Optik.

I will try what you suggest. I'm a bit confused though, as I've simply adapted examples out of my Teach Yourself ASP.Net in 21 Days Book. Would you be able to shed a little light on why I need to use objDataReader(CommandBehavior.CloseConnection)? What was it that I was doing wrong?
Many thanks
Shaun


Hi Optik

I would just like to say that this did infact solve the problem. So this issue is now resolved.

It would be good if I could just understand why!?!

Many thanks for your time

Shaun


Quoted from MSDN
"While theSqlDataReader is in use, the associatedSqlConnection is busy serving theSqlDataReader. While in this state, no other operations can be performed on theSqlConnection other than closing it. This is the case until you call theSqlDataReader.Close method. If theSqlDataReader is created withCommandBehavior set toCloseConnection, closing theSqlDataReader closes the connection automatically."


Cheers me dears!

The continuing adventures of a ASP newb

Hi there,

OK - So I have run into a problem. I have created a shopping cart, the cart is an object that gets created when the user logs in. That all works great. My problem is this.

I have a page for viewing the cart, what I want to do is loop through the cart and show the details for all the items. I mean I could just bind it to a datagrid view (I think) but I would like a little more control over that. The problem is if I loop through my array and say print some HTML it prints it first thing on the page :( That of course doesn't work... How can I get it to put my HTML where I want it? Like inside of a DIV tag?

Being a total newb to ASP programming I am not sure what the best approach to something like this is. But there has to be a lot of cases where a web page has some sort of object of varying length and it needs to be printed to the page in some fashion.

Can anyone point me in the right direction?

ThanksPlace an asp label with runat =server within the div tag. Then send the html output to it in the code behind:

<div>
<asp:Label runat="server" id="myLabel"></asp:Label>
</div>

Then in the code behind:
myLabel.Text = ...

F
Hi there,

OK - So I have run into a problem. I have created a shopping cart, the cart is an object that gets created when the user logs in. That all works great. My problem is this.

I have a page for viewing the cart, what I want to do is loop through the cart and show the details for all the items. I mean I could just bind it to a datagrid view (I think) but I would like a little more control over that. The problem is if I loop through my array and say print some HTML it prints it first thing on the page :( That of course doesn't work... How can I get it to put my HTML where I want it? Like inside of a DIV tag?

Being a total newb to ASP programming I am not sure what the best approach to something like this is. But there has to be a lot of cases where a web page has some sort of object of varying length and it needs to be printed to the page in some fashion.

Can anyone point me in the right direction?

Thanks
That was a very fundamental ASP.NET question. Are you sure you should be creating a shopping cart? :ehh:

Because of the nature of your question, I take it you don't have a lot of knowledge of the ASP.NET controls. First thing to remember, do not use Response.Write. That's something from the classic ASP days which you should rarely ever need to use.

Tutorial:
http://www.asp.net/Tutorials/quickstart.aspx

Saturday, March 24, 2012

The DataSet: I have doubts

Here are my doubts about the dataSet object. These doubts may arise from my not understanding this object properly so please let me know if this is the case.

i see these problems:

1. if a user closes the page mid session i lose my in memory dataSet so all the dataGrid editing my user has done since the database was last updated is lost.

2. when updating the parent database I need to fill the dataAdapter first in case anyone else has edited the rows beforehand. all this toing and froing is expensive.

Also, how do i decide to update the parent database from the dataSet. Can I do it automatically i.e. on a timer or do I do it after every 5 dataGrid row edits?

thanks.1. You would lose any data had you hand written the text boxes and filled the table dynamically with them. It's not the fault of the DataSet or some weird communication.

2. Again, you should be checking data validity before hand any way. The only difference here, with DataGrids, is that you know exactly which row was modified before hand very easily.

3. [How do I...] Why not whenever the user presses update? The few times that I have used datasets I have never held them in the session. I bind them to a datagrid and forget. When the user edits, the info I need to update the row is right there.

The difference between creating an instance of an object

Could someone tell me in plain english was is the difference between


Dim MyObject As SomeType

and


Dim MyObject As New SomeType

and


Dim MyObject = New SomeType
Dim MyObject as SomeType = Creating a variable that holds an object of SomeType.

Dim MyObject as New SomeType = Creating and instantiating an object of SomeType.

Dim MyObject = New SomeType = Invalid syntax in vb.net. You need to specify the default type as variant is no longer supported in ASP.NET.
Ok, now I understand.

So if I have something like Fruit.Apple and Value is part of this as in Fruit.Apple.Value, I can do this...

Dim Food As Fruit.Apple

Food.Value

It looks like a way of shortening the name of an object.

Now, I have another question. How do you know when is the appropriate time to create and instantiate a new object rather than just use the above method?

Sorry if my question seems too easy, but I didn't do much of this stuff in regular ASP.
Well yes and no.

Lets think of this another way. Lets take your Fruit object. Your fruit has properties - color, weight, type, etc. You would create a class that describes this like so:


Public Class Fruit
Private _type As String
Private _color As String
Private _weight As Decimal

Public Property Type() As String
Get
Return _type
End Get
Set(ByVal Value As String)
_type = Value
End Set
End Property
' Add other properties for color and weight also

End Class

Then in your code you would instantiate a new Fruit object like:


Dim objFruit as New Fruit
'Then set properties of the fruit
With objFruit
.Type = "Apple"
.Color = "Red"
.Weight = 2.2
End With

It is appropriate to create a class whenever you are going to possibly reference the object from multiple places in your code.

Greg

The easiest way to save data into a text file on server side - Help me please

Embarrassed

Hi guys, I'm new at ASP and all I wanna know is, what is the simplest code for gathering info from my website visitors (using the FORM object) and saving it to a text file (*.TXT) on the web server? The whole procedure. I know it's lame, but is there anyone out there, that could help me with this one? Thanks guys.

Andrew

You could do something like the following. Here txtName and txtAddress are textboxes. Similarly you can add all the controls that you want to save.

The collected data is saved in the current directory on the webserver in a file called Test.txt. All subsequent saves will be appended to the same file (change the last parameter
to false to overwrite on every save)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim s As String
s += txtName.Text + vbCrLf
s += txtAddress.Text + vbCrLf
My.Computer.FileSystem.WriteAllText(Server.MapPath("Test.txt"), s, True)

end sub