ASP .NET - Email Link,Article,Recipe...To Friend

Discussion in 'ASP.NET / ASP.NET Core' started by Ex-designz, Jul 3, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. This code is use to send any links you want to a friend. I had this running on my ASP 3 website, so I decided to convert it.


    VIEW LIVE DEMO: http://www.myasp-net.com/recipedetail.aspx?id=1361


    ' recipedetail.aspx page

    Public strRName as string
    Public strCName as string

    In the datareader SQL put these code.

    'Read data
    objDataReader.Read()

    strRName = objDataReader('Name')
    strCName = objDataReader('Category')

    The reason why I declared them public, so I can place the Recipe Name and Category anywhere in the document.

    On your article_id,linkview or any detail pages. You will have to code a link tag to open the emailrecipe.aspx.
    link tag code:
    <a class='dt' title='Email <%=strRName%> recipe to friend' href='javascript:eek:penWindow('emailrecipe.aspx?url=http://www.myasp-net.com/recipedetail.aspx?id=
    <%=Request.QueryString('id')%>&n=<%=strRName%>&c=<%=strCName%>')'>Email Recipe</a>

    --------------------------------------------End recipedetail.aspx----------------


    ' Code emailrecipe.aspx. Copy the whole code in notepade and name it emailarticle or ....

    Note: This variables are coming from querystring parameter of the recipdetail.aspx page.
    Dim strName as string = Request.QueryString('n')
    Dim strCat as string = Request.QueryString('c')
    Request.QueryString('url')


    <%@ Page Language='VB' Debug='True'%>
    <%@ Import Namespace='System.Web.Mail' %>

    <script language='VB' runat='server'>

    Sub Page_Load(Source As Object, E As EventArgs)

    If Not Page.IsPostBack Then

    Dim strName as string = Request.QueryString('n')
    Dim strCat as string = Request.QueryString('c')
    Dim strBody As String

    strBody = 'Hi Friend,' & vbCrLf & vbCrLf _
    & 'I thought you might be interested in this recipe I found at www.ex-designz.net:' & vbCrLf & vbCrLf _
    & 'Recipe Name: ' & strName & vbCrLf _
    & 'Category: ' & strCat & vbCrLf _
    & vbCrLf _
    & Request.QueryString('url') & vbCrLf

    txtMessage.Text = strBody
    End If
    End Sub


    Sub btnSendMsg_OnClick(Source As Object, E As EventArgs)

    Dim Messagesnd As New MailMessage
    Dim sndingmail As SmtpMail

    If Page.IsValid() Then

    Messagesnd.From = txtFromEmail.Text
    Messagesnd.To = txtToEmail.Text
    Messagesnd.Subject = txtFromName.Text & ' has emailed you ' & Request.QueryString('n') & ' recipe'
    Messagesnd.Body = txtMessage.Text & vbCrLf _
    & 'This message was sent from: ' _
    & Request.ServerVariables('SERVER_NAME') & '.' _
    & vbCrLf & vbCrLf _
    & 'This email was sent to ' & txtToEmail.Text & '.'

    ' SMTP server's name,localhost or ip address!
    sndingmail.SmtpServer = 'localhost'
    sndingmail.Send(Messagesnd)

    Panel1.Visible = False

    lblsentmsg.Text = 'Your message has been sent to ' _
    & txtToEmail.Text & '.'
    End If

    End Sub

    </script>


    <html>
    <head>
    <title>Sending Recipe To a Friend</title>
    <style type='text/css' media='screen'>@import 'cssreciaspx.css';</style>
    </head>

    <asp:panel ID='Panel1' runat='server'>
    <form runat='server'>
    <table align='center' cellspacing='0' cellpadding='0' width='40%'>
    <tr><td>

    <div align='center'><h2>Sending <%=Request.QueryString('n')%> Recipe to a Friend</h2></div>
    <table border='0' cellspacing='1' cellpadding='1' width='100%'>
    <tr>
    <td valign='top' align='right' class='content6'>Your Name:</b></td>
    <td>
    <asp:TextBox id='txtFromName' size='25' cssClass='textbox' runat='server' />
    <asp:RequiredFieldValidator runat='server'
    id='validNameRequired' ControlToValidate='txtFromName'
    cssClass='cred2' errormessage='* Name:'
    display='Dynamic' />
    </td>
    </tr>
    <tr>
    <td valign='top' align='right' class='content6'>Your Email:</b></td>
    <td>
    <asp:TextBox id='txtFromEmail' size='25' cssClass='textbox' runat='server' />
    <asp:RequiredFieldValidator runat='server'
    id='validFromEmailRequired' ControlToValidate='txtFromEmail'
    cssClass='cred2' errormessage='* Email:'
    display='Dynamic' />
    <asp:RegularExpressionValidator runat='server'
    id='validFromEmailRegExp' ControlToValidate='txtFromEmail'
    ValidationExpression='^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$'
    cssClass='cred2' errormessage='Not Valid'
    Display='Dynamic' />
    </td>
    </tr>
    <tr>
    <td valign='top' align='right' class='content6'>Friend's Name:</b></td>
    <td>
    <asp:TextBox id='toname' size='25' cssClass='textbox' runat='server' />
    <asp:RequiredFieldValidator runat='server'
    id='validFriendNameRequired' ControlToValidate='toname'
    cssClass='cred2' errormessage='* Name:'
    display='Dynamic' />
    </td>
    </tr>
    <tr>
    <td valign='top' align='right' class='content6'>Friend's Email:</b></td>
    <td>
    <asp:TextBox id='txtToEmail' size='25' cssClass='textbox' runat='server' />
    <asp:RequiredFieldValidator runat='server'
    id='validToEmailRequired' ControlToValidate='txtToEmail'
    cssClass='cred2' errormessage='* Email:'
    display='Dynamic' />
    <asp:RegularExpressionValidator runat='server'
    id='validToEmailRegExp' ControlToValidate='txtToEmail'
    ValidationExpression='^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$'
    cssClass='cred2' errormessage='Not Valid:'
    Display='Dynamic' />
    </td>
    </tr>
    <tr>
    <td colspan='2'>
    <asp:TextBox id='txtMessage' cssClass='textbox' Cols='50' TextMode='MultiLine'
    Rows='10' ReadOnly='True' runat='server' />

    <asp:Button id='btnSend' cssClass='submit' Text='Send Recipe'
    OnClick='btnSendMsg_OnClick' runat='server' />
    </td>
    </tr>
    </table>
    </td></tr>
    </table>
    </form>
    </asp:panel>
    <div style='text-align: center;' class='content2'><asp:HyperLink runat='server' NavigateUrl='JavaScript:eek:nClick= window.close()' class='content2'>Close Window</asp:HyperLink></div>


    <asp:Label cssClass='content2' id='lblsentmsg' runat='server' />
    </body>
    </html>


    Have fun!

    Dexter
    www.ex-designz.net
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page