DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 14 Aug 2007 16:14:39 -0400,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    dancer
          2    Peter Bromberg [C# MVP]
          3    Alexey Smirnov
          4    Alexey Smirnov
          5    dancer
          6    Alexey Smirnov


Results to both Database AND email   
How do I send results of a form page to both email AND a database.  I have a 
page which works with this sub:

Sub btnSendMail_OnClick(Source As Object, E As EventArgs)

And I have a page which works with this sub:

Sub btnSendDatabase_OnClick(Source As Object, E As EventArgs)

How do I combine the two?  I tried putting the second sub within the first, 
but got this error message:
"Statement cannot appear within a method body. End of method assumed."
Date:Tue, 14 Aug 2007 16:14:39 -0400   Author:  

RE: Results to both Database AND email   
As a general rule, its not a good idea to put business logic inside event 
handlers such as "button_click". To make it really OOP you want to have the 
business logic in methods of a class library. In the Button_Click, you would 
make one call to your library's database "thing" and another to its (or 
another library's)  "email" thing. Hope that makes sense.
-- Peter
Recursion: see Recursion
site:  http://www.eggheadcafe.com
unBlog:  http://petesbloggerama.blogspot.com
BlogMetaFinder:    http://www.blogmetafinder.com



"dancer" wrote:


> How do I send results of a form page to both email AND a database.  I have a 
> page which works with this sub:
> 
> Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
> 
> And I have a page which works with this sub:
> 
> Sub btnSendDatabase_OnClick(Source As Object, E As EventArgs)
> 
> How do I combine the two?  I tried putting the second sub within the first, 
> but got this error message:
> "Statement cannot appear within a method body. End of method assumed."
> 
> 
> 
> 
> 
Date:Tue, 14 Aug 2007 13:26:02 -0700   Author:  

Re: Results to both Database AND email   
On Aug 14, 10:14 pm, "dancer"  wrote:

> How do I send results of a form page to both email AND a database.  I have a
> page which works with this sub:
>
> Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
>
> And I have a page which works with this sub:
>
> Sub btnSendDatabase_OnClick(Source As Object, E As EventArgs)
>
> How do I combine the two?  I tried putting the second sub within the first,
> but got this error message:
> "Statement cannot appear within a method body. End of method assumed."


1) Move the code out of the onclick-methods:

Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
SendDatabase()
SendEmail()
End Sub

Sub btnSendDatabase_OnClick(Source As Object, E As EventArgs)
SendDatabase()
SendEmail()
End Sub

Sub SendDatabase()
' Code to save data
.....
End Sub

Sub SendEmail()
' Code to send email
.....
End Sub

2) Change event handler of your buttons to the same method.

Create new method

Protected Sub SendDatabaseAndEmail(Source As Object, E As EventArgs)
Handles btnSendMail.Click, btnSendDatabase
' Code to save database and email
....
End Sub

And delete btnSendDatabase_OnClick and btnSendMail_OnClick methods
Date:Tue, 14 Aug 2007 13:32:16 -0700   Author:  

Re: Results to both Database AND email   
On Aug 14, 10:32 pm, Alexey Smirnov  wrote:

> Protected Sub SendDatabaseAndEmail(Source As Object, E As EventArgs)
> Handles btnSendMail.Click, btnSendDatabase


must be

Protected Sub SendDatabaseAndEmail(Source As Object, E As EventArgs)
Handles btnSendMail.Click, btnSendDatabase.Click
Date:Tue, 14 Aug 2007 13:33:45 -0700   Author:  

Re: Results to both Database AND email   
Forgive me for being so dumb, but are you saying, do 1) *OR* 2)?
Or are you saying do 1) *and* 2)?

Thank you.

"Alexey Smirnov"  wrote in message 
news:1187123536.209561.229870@g4g2000hsf.googlegroups.com...

> On Aug 14, 10:14 pm, "dancer"  wrote:
>> How do I send results of a form page to both email AND a database.  I 
>> have a
>> page which works with this sub:
>>
>> Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
>>
>> And I have a page which works with this sub:
>>
>> Sub btnSendDatabase_OnClick(Source As Object, E As EventArgs)
>>
>> How do I combine the two?  I tried putting the second sub within the 
>> first,
>> but got this error message:
>> "Statement cannot appear within a method body. End of method assumed."
>
> 1) Move the code out of the onclick-methods:
>
> Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
> SendDatabase()
> SendEmail()
> End Sub
>
> Sub btnSendDatabase_OnClick(Source As Object, E As EventArgs)
> SendDatabase()
> SendEmail()
> End Sub
>
> Sub SendDatabase()
> ' Code to save data
> ....
> End Sub
>
> Sub SendEmail()
> ' Code to send email
> ....
> End Sub
>
> 2) Change event handler of your buttons to the same method.
>
> Create new method
>
> Protected Sub SendDatabaseAndEmail(Source As Object, E As EventArgs)
> Handles btnSendMail.Click, btnSendDatabase
> ' Code to save database and email
> ...
> End Sub
>
> And delete btnSendDatabase_OnClick and btnSendMail_OnClick methods
> 
Date:Tue, 14 Aug 2007 17:26:53 -0400   Author:  

Re: Results to both Database AND email   
On Aug 14, 11:26 pm, "dancer"  wrote:

> Forgive me for being so dumb, but are you saying, do 1) *OR* 2)?


Yes, it's either 1) OR 2)

In 1) you will have two separated methods (as it is now in your code)
for two buttons/events. Both methods will call two other new methods
SendDatabase() and SendEmail(), where you should place your
correspondent code. You also can combine these two methods in one, say
SendDatabaseAndEmail()

for example

Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
SendDatabaseAndEmail()
End Sub

Sub btnSendDatabase_OnClick(Source As Object, E As EventArgs)
SendDatabaseAndEmail()
End Sub

Sub SendDatabaseAndEmail()
' Code to save data and send an email
.....
End Sub

In 2) I suggested to use point both events to the same method.

As Peter said, it's not always a good idea to put business logic
inside "button_click". As you can see from my examples it's more easy
sometimes to have it in a separated methods and if, for example, you
would need to send an email from other web forms as well, it's really
make sense to move SendEmail() to a class library which can be
accessed from other pages.
Date:Tue, 14 Aug 2007 14:51:20 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us