473,394 Members | 1,829 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,394 software developers and data experts.

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."


Aug 14 '07 #1
5 1293
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."


Aug 14 '07 #2
On Aug 14, 10:14 pm, "dancer" <dan...@microsoft.comwrote:
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

Aug 14 '07 #3
On Aug 14, 10:32 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
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
Aug 14 '07 #4
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" <al************@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
On Aug 14, 10:14 pm, "dancer" <dan...@microsoft.comwrote:
>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

Aug 14 '07 #5
On Aug 14, 11:26 pm, "dancer" <dan...@microsoft.comwrote:
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.

Aug 14 '07 #6

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

Similar topics

6
by: Alan | last post by:
I'm just about to start a project that needs to combine the results of a SQL Server query with the results of an Index Server query. The basic idea is that the user enters/selects a bunch of search...
14
by: CJM | last post by:
I have a query which produces different results in the Access query builder and in an ASP page (via ADO) An example of the query is: ----------------------------------------------------------...
2
by: Jegg | last post by:
I wrote a web app using an ASP front end (not .NET) connecting to a SQL Server 2000 (no SP) back end. Both the web server and the database server are Windows 2003 boxes. The app was running fine...
2
by: Alex Scollay | last post by:
Let's say I have a column whose values are all 2-digit integers, e.g. 82 (though it's actually a varchar field). From now on, the column will be able to have 2-digit as well as 3-digit integers....
0
by: Benman | last post by:
Hi everyone, I was looking for a way to execute an .ASP page through the windows scehduler, and I found several posts that showed out to "run" a URL using a windows scripting file. The file...
13
by: guitarromantic | last post by:
Hey everyone. I'm editing some stuff I did last summer, trying to bugfix and improve stuff. One improvement (or an oversight of the original design) is adding dynamic <title> tags to my pages....
1
by: premgrps | last post by:
Hi, I have a table of a million records and wrote a CGI-PERL script to display the results based on the user input. The results might be anywhere from 100 to 1000 per query and presently I am...
21
by: bruno_guedesav | last post by:
I've made a function to fetch all results as an array of result- arrays. Getting the result arrays is easy, via mysql_fetch_array, and function itself is quite simple, as follows: function...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.