Hey there!

I need your help. Just small fixing. Im brand-new to C#.

I got the email from gmail account - look at the data (bold):

Name: xxxx
Surname: xxxx
Email: xxxx
Description:Card A6
Order:true // no data --- It should be : Order: Images/order_names/faithcard.jpg

Code behind (C#):

msg += "Name: " + txtName.Text; //correct
        msg += "<br>Surname: " + txtSurname.Text; //correct
        msg += "<br>Email: " + txtEmail.Text; //correct
        msg += "<br>Description:" + description.Value; // correct
        msg += "<br>Order:" + [B]group1[/B].Visible;// Error. replace something with Visible??

I have put runat="server" in optgroup tag instead of select tag - it is working because there is no displaying compile error

Markup:

<select name="order" multiple="multiple" size="12" style="width:330px;" id="dlist1" onchange="swapImage1()">
        <optgroup label="Sow Seeds of Love" [B]id="group1" runat="server"[/B]>
            <option selected="selected" value="Images/NoneImage.gif">None</option>
            <option data-card="32.00" data-memo="62.00" data-tags1="1.80"  data-tags4="8.50"  data-key="30.00" data-fridge="40.00" data-flower_sachet="----" value="Images/Order_names/SowSeeds/Faith01_yellow.jpg">Faith</option>
</optgroup>

What must I replay with Visible to display data (Order: Images/order_names/faithcard.jpg)?

Thanks for reply. I know how to display images when selected item but what i mean i want to make accessible data to my gmail account after you filled a form and clicking send email button.

I only saw order:true in the email I received. I dont want this. I want it to display like Order:Images/Order_names/SowSeed/Grace01_green.jpg" in the email.

Hope you understand it. Please review my codes (above) You will see what I mean. :-)

Thanks for your time. I appreciate it :-)

Member Avatar for stbuchok

Do you want the string (ie. Images/Order_names/SowSeed/Grace01_green.jpg) to appear or the actual image?

If it's the string, you should really look at the demo I sent you.

Yes it is string I am talking about but I cannot see it in the email after you filled a order form and clicking send email button. I should know what you want to order image (like Images/Order_names/SowSeeds/Faith01_yellow.jpg). How to display this data in the email. I think I better copy full markup and code behind so that you can see what I am doing.

Markup (remember Im using masterpage):

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Contact.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

    <link href="CSS/StyleSheet.css" rel="stylesheet" type="text/css" />
    <script src="Java/Prices.js" type="text/javascript"></script>
    <script src="Java/Images1.js" type="text/javascript"></script>
   
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">



    <div id="OrderContent">

<p>Please complete the following details & we will be in touch as soon as possible:</p>
   
<form id="Form1" method="post" enctype="text/plain" runat="server">


 <table>
  <tr>
    <td>
      <label>Name:</label>
    </td>
    <td>
      <label><asp:TextBox ID="txtName" runat="server" placeholder="" required Width="210px"></asp:TextBox></label>
   </td>
  </tr>
  <tr>
    <td>
      <label>Surname:</label></td>
    <td>
      <label><asp:TextBox ID="txtSurname" runat="server" placeholder="" required Width="210px"></asp:TextBox></label>
    </td>
  </tr>
  <tr>
    <td>
      <label>E-mail:</label>
    </td>
    <td>
      <label><asp:TextBox ID="txtEmail" runat="server" placeholder="" required Width="210px"></asp:TextBox></label>
    </td>
  </tr>
  <tr>
</table>
        

<table>
<tr>
 <td>
  <p>Order the following:</p>

<select name="order" multiple="multiple" size="12" style="width:330px;" id="dlist1" onchange="swapImage1()">
<optgroup label="Sow Seeds of Love[B]" id="group" runat="server"[/B]> //Instead of select tag because I got no compile error and even I got data in email like order="true" it almost working but i need full data like order:Images/Order_names/SowSeeds/Faith01_yellow.jpg instead of "true"
            <option data-card="32.00" data-memo="62.00" data-tags1="1.80"  data-tags4="8.50"  data-key="30.00" data-fridge="40.00" data-flower_sachet="----" value="Images/Order_names/SowSeeds/Faith01_yellow.jpg">Faith</option>
            <option data-card="32.00" data-memo="62.00" data-tags1="1.80"  data-tags4="8.50"  data-key="30.00" data-fridge="40.00" data-flower_sachet="----" value="Images/Order_names/SowSeeds/Grace01_green.jpg">Grace</option>
</optgroup>
</select>
 </td>
 <td>
    <img class="ImageToSwap" id="imageToSwap1" src="Images/NoneImage.gif" width="147" height="195" />
 </td>
</tr>
</table>
   

<table>
    <tr>
        <td>Description:</td>
        <td class="style1">Price (ZAR):</td>
    </tr>
</table>

<table>
        <tr>
            <td class="style3"><label><input type="checkbox" name="description" value="Card A6" id="description" runat="server" /> Card A6 (blank)</label></td>
            <td id="price_card"></td>
        </tr>
        <tr>
            <td class="style3"><label><input type="checkbox" name="description" value="Memo Book A6" id="description" runat="server" /> Memo Book A6</label></td>
            <td id="price_memo"></td>
        </tr>
</table>
<br />




 <p><asp:Button ID="Send" runat="server" Text="Send Email" onclick="Send_Click"
         style="height: 26px"/>
<input type= "reset" value="Clear" /></p>

</form>
</div>

</asp:Content>

Code behind (C#):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Send_Click(object sender, EventArgs e)
    {

        string msg = "---------------------------<br>";
        string from = "XXXX@gmail.com"; //Replace this with your own correct Gmail Address
        string to = "XXXXX@gmail.com"; //Replace this with the Email Address to whom you want to send the mail

        MailMessage mail = new MailMessage();
        mail.To.Add(to);
        mail.From = new MailAddress(from, "Ellie Rose", System.Text.Encoding.UTF8);
        mail.Subject = "Customer Order from Ellie Rose Website";
        mail.SubjectEncoding = System.Text.Encoding.UTF8;
        msg += "Name: " + txtName.Text;
        msg += "<br>Surname: " + txtSurname.Text;
        msg += "<br>Email: " + txtEmail.Text;

        msg += "<br>Order:" + group.Attributes.Add("order", "Images/Order_names/..."); // it is from optgroup tag (i already included runat="server" and id="group") I tried to change it instead of group.Visible; (only display "true") but not working.
        msg += "<br>Description:" + description.Value; //description.Checked;
        mail.Body = msg;
        mail.BodyEncoding = System.Text.Encoding.ASCII;
        mail.IsBodyHtml = true;
        mail.Priority = MailPriority.High;

        SmtpClient client = new SmtpClient();
        //Add the Creddentials- use your own email id and password

        client.Credentials = new System.Net.NetworkCredential(from, "mypassword");

        client.Port = 587; // Gmail works on this port
        client.Host = "smtp.gmail.com";
        client.EnableSsl = true; //Gmail works on Server Secured Layer
        try
        {
            client.Send(mail);
        }
        catch (Exception ex)
        {
            Exception ex2 = ex;
            string errorMessage = string.Empty;
            while (ex2 != null)
            {
                errorMessage += ex2.ToString();
                ex2 = ex2.InnerException;
            }
            HttpContext.Current.Response.Write(errorMessage);
        } // end try
        Response.Redirect("Thanks.aspx");
    }
}
Member Avatar for stbuchok

ok, then please take a look at the demo, it has your answer

okay thanks it seems i got answer but damn it is VB.NET from your link. You know how to translate it to C#, dont you? If not, that is okay and thanks again for your time. :-)

Sorry to disurb you again. I managed translation :-)

I did the same as this demo. Look at my codes:

markup:

<select name="order" multiple="multiple" size="12" style="width:330px;" [B]id="dlist1" runat="server"[/B] onchange="swapImage1()">
  <optgroup label="Sow Seeds of Love">
    <option data-card="32.00" data-memo="62.00" data-tags1="1.80"  data-tags4="8.50"    data-key="30.00" data-fridge="40.00" data-flower_sachet="----" value="Images/Order_names/SowSeeds/Faith01_yellow.jpg">Faith</option>
  </optgroup>
</select>

code behind:

msg += "<br>Order:" + dlist1.Value;

When I debug it, I got compile error:

'HtmlSelect' cannot have children of type 'LiteralControl'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 'HtmlSelect' cannot have children of type 'LiteralControl'.

Source Error:

Line 114:<p class="style1">Order the following:</p>
Line 115:
Line 116:<select name="order" size="12" style="width:330px;" id="dlist1" runat="server" onchange="swapImage1()">
Line 117: <optgroup label="Sow Seeds of Love">
Line 118: <option selected="selected" value="Images/NoneImage.gif">None</option>

Member Avatar for stbuchok

From what I can tell it's because of the optgroup. Try it without the optgroup to see if it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.