Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Email Confirmation From FormView control after inserting data

Posted on 2010-08-23
6
Medium Priority
?
559 Views
Last Modified: 2012-05-10
I have a web app with a formview control to insert data into a sql database. I want to send a notification email of newly inserted data. can somebody please tell me how to do this?
0
Comment
Question by:MMBS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:Stephan
ID: 33508206
You can use the ItemInserted event on the FormView.
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 33509290
Write your mail sending code in a function and call that function on  FormView's ItemInserted Event
Check following link for ItemInserted Event code
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.iteminserted.aspx

Hope this will help you.
Regards,
Ram
0
 

Author Comment

by:MMBS
ID: 33517432
Thanks for the info. I used the itemInstered event but I still do not get any eamils. I do not get any errors messages either. Here is my code. What am I diong wrong?

----Web.config---









----Form Page----


<script runat="server">
    Sub EmployeeFormView_ItemInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)
        ' Use the Exception property to determine whether an exception
        ' occurred during the insert operation.
        If e.Exception Is Nothing Then
            ' Use the AffectedRows property to determine whether the
            ' record was inserted. Sometimes an error might occur that
            ' does not raise an exception, but prevents the insert
            ' operation from completing.
            If e.AffectedRows = 1 Then
                MessageLabel.Text = FormView1.DataItem("Description")
                e.KeepInInsertMode = False
            End If
        Else
            ' Insert the code to handle the exception.
            MessageLabel.Text = e.Exception.Message
            ' Use the ExceptionHandled property to indicate that the
            ' exception has already been handled.
            e.ExceptionHandled = True
            e.KeepInInsertMode = False
        End If
    End Sub
    Sub Email()
        Dim credential As New System.Net.NetworkCredential("Domain\User", "Password")
        Dim message As New System.Net.Mail.MailMessage()
        Dim client As New System.Net.Mail.SmtpClient()
        client.Credentials = credential
       
        message.From = New System.Net.Mail.MailAddress("FromUser@Domain.com.au")
        message.To.Add(New System.Net.Mail.MailAddress("ToUser@Domain.com.au"))
        message.Subject = "blah blah vlah!"
        message.Body = MessageLabel.Text
        message.IsBodyHtml = True
        client.Send(message)
    End Sub
   
</script>
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 33518052
Hi MBBS,
I think there is nothing wrong in your code, but you have not called sub email anywhere. So just it as below:

Sub EmployeeFormView_ItemInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)

       ' Use the Exception property to determine whether an exception
       ' occurred during the insert operation.
       If e.Exception Is Nothing Then

           ' Use the AffectedRows property to determine whether the
           ' record was inserted. Sometimes an error might occur that
            ' does not raise an exception, but prevents the insert
           ' operation from completing.
           If e.AffectedRows = 1 Then

               MessageLabel.Text = FormView1.DataItem("Description")
                e.KeepInInsertMode = False
               Email()      

           End If

       Else

           ' Insert the code to handle the exception.
           MessageLabel.Text = e.Exception.Message

           ' Use the ExceptionHandled property to indicate that the
            ' exception has already been handled.
           e.ExceptionHandled = True
           e.KeepInInsertMode = False

       End If

   End Sub

   Sub Email()
       Dim credential As New System.Net.NetworkCredential("Domain\User", "Password")
       Dim message As New System.Net.Mail.MailMessage()
       Dim client As New System.Net.Mail.SmtpClient()
       client.Credentials = credential
     
        message.From = New System.Net.Mail.MailAddress("FromUser@Domain.com.au")
       message.To.Add(New System.Net.Mail.MailAddress("ToUser@Domain.com.au"))
       message.Subject = "blah blah blah!"
       message.Body = MessageLabel.Text
       message.IsBodyHtml = True
       client.Send(message)
   End Sub


Hope this will help you.
Regards,
Ram
0
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 2000 total points
ID: 33518062
MMBS,
Sorry for writing your name wrong.

Regards,
Ram
0
 

Author Comment

by:MMBS
ID: 33527260
Thanks Ram, you have me help a lot. I am getting the emails now but I am not getting the inserted value from textbox  in the formview control. Am I doing this correctly with the following code?
The TextBox ID is Description.
MessageLabel.Text = FormView1.DataItem("Description")
Rgards,
MMBS
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question