Loading ...

urgent - problem html tags in asp.net

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  web forms / data controls   » urgent - problem html tags in asp.net

urgent - problem html tags in asp.net

Posts under the topic: urgent - problem html tags in asp.net

Posted: 7/5/2011

Lurker 55  points  Lurker
  • Joined on: 7/5/2011
  • Posts: 11

Hey there!

Im developing website using asp.net and html mixed.

So I rather chose to use html select tag and checkbox tag. Contact.aspx.cs (behind code) doesn't recognise it because it is html tags. Is there a way to recognise html tags behind codes?? Look at below codes (bold):

Contact.aspx:

<select name="order" multiple="multiple" id="dlist1" 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 Card</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 Card</option>     
        </optgroup>
        <optgroup label="Goosebumps Vintage A">
            <option data-card="32.00" data-memo="62.00" data-tags1="1.80" data-tags4="----"  data-key="30.00" data-fridge="40.00" data-flower_sachet="----" value="Images/Order_names/GoosebVA/GoosebumpVA_blue.jpg">Blue</option>
        </optgroup>

</select>

<table>

        <tr>
            <td class="style3"><input type="checkbox" name="description" value="Card A6" id="description" /> Card A6 (blank)</td>
        </tr>

</table>

Contact.aspx.cs:

 msg += "Name: " + txtName.Text; // fine
        msg += "<br>Surname: " + txtSurname.Text; // fine
        msg += "<br>Email: " + txtEmail.Text; // fine
        msg += "<br>Order:" + HtmlTextWriterTag.Select.ToString("dlist1"); // belong to select tag

          msg += "<br>Order:" + HtmlTextWriterTag.....  // belong to checkbox tag - how?

        mail.Body = msg;
        mail.BodyEncoding = System.Text.Encoding.ASCII;

Hope you can help fix it! Your help much appreciated. It is urgent. Thank you!


Posted: 7/5/2011

Starter 727  points  Starter
  • Joined on: 6/6/2011
  • Posts: 74

Hi Natalie,

If you want html tags to be visible at code behind, you should add tag 'runat="server"', like this

<input type="checkbox" name="description" value="Card A6" id="description" runat="server" />

Best Regards,

Gjorgji


Posted: 7/5/2011

Lurker 55  points  Lurker
  • Joined on: 7/5/2011
  • Posts: 11

I followed your instruction. But when I debug it, error occurs. Look at this attachment.

I have inserted using System.Web.UI.HtmlControls; in code behind.

Why it not working? Sorry to bother you again but appreciate your value help.

Thanks for your time :-)

 

 


Posted: 7/5/2011

Lurker 55  points  Lurker
  • Joined on: 7/5/2011
  • Posts: 11

I followed your instruction. But when I debug it, error occurs. Look at this attachment.

I have inserted using System.Web.UI.HtmlControls; in code behind.

Why it not working? Sorry to bother you again but appreciate your value help.

Thanks for your time :-)

 

 


Posted: 7/6/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Hi,

You can get them via Request.Form["order"] and Request.Form["description"] 
Code:

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <select name="order" multiple="multiple" id="dlist1" 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 Card</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 Card</option>
        </optgroup>
        <optgroup label="Goosebumps Vintage A">
            <option data-card="32.00" data-memo="62.00" data-tags1="1.80" data-tags4="----" data-key="30.00"
                data-fridge="40.00" data-flower_sachet="----" value="Images/Order_names/GoosebVA/GoosebumpVA_blue.jpg">
                Blue</option>
        </optgroup>
    </select>
    <table>
        <tr>
            <td class="style3">
                <input type="checkbox" name="description" value="Card A6" id="description" />
                Card A6 (blank)
            </td>
        </tr>
    </table>
    <asp:Button ID="SubmitButton" runat="server" Text="Button" />
    </form>
</body>
</html>

<script runat="server">


    protected void Page_Load(object sender, EventArgs e)
    {
        var order = Request.Form["order"];
        var description = Request.Form["description"];
    }
</script>



Posted: 7/6/2011

Lurker 55  points  Lurker
  • Joined on: 7/5/2011
  • Posts: 11

Hey Raghav

Thanks for your reply. Appreciate it! Glad I dont get compile error but unfortnately it is not working after I copied your codes in the markup because I just checked my gmail account that the email didnt include this data (order and description). Sigh!

But the email only included the data (Name, surname and email address). Look at this screenshot picture.

Look my codes below (its working fine):

    protected void Send_Click(object sender, EventArgs e)
    {

      string msg = "---------------------------<br>";

        msg += "Name: " + txtName.Text;
        msg += "<br>Surname: " + txtSurname.Text;
        msg += "<br>Email: " + txtEmail.Text;

        var order = Request.Form["order"];
        var description = Request.Form["description"];
//I also have tried to move
your codes in send_click event from page_load but it is also not working.

       string selectedValue = dlist1.Value; // I have tried another way even I put runat="server" attribute in the html tags - got compile error.

    }


I have been trying to several ways to solve it but still not this data in email. Strange! Thanks for your time :-)

 

 


Posted: 7/6/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

I am sure the code I have given will work. Show your Page Load code and tell me where did you put my code?


Posted: 7/6/2011

Lurker 55  points  Lurker
  • Joined on: 7/5/2011
  • Posts: 11

I have put your code in the markup and it is not working then I put it in code behind - also not working (C#) :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
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)
    {
        var order = Request.Form["order"];
        var description = Request.Form["description"];
    }

    protected void Send_Click(object sender, EventArgs e)
    {
        string msg = "---------------------------<br>";
        string from = "myemail@gmail.com"; //Replace this with your own correct Gmail Address
        string to = "myemail@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;
        //string selectedValue = dlist1.Value;
       // msg += "<br>Order:" + dlist1.SelectedIndex;
       // msg += "<br>Order:" + HtmlTextWriterTag.Select.ToString("dlist1");
       // msg += "<br>Description:" + HtmlTextWriterTag.Select.ToString("
        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");
    }
}

 

If there is no way to solve it, maybe i can send my zip file to you so that you can see what is wrong if you dont mind. If you refuse, i will understand :-) If that is okay with you, can you send your email address to me so that I can email attachment to you. My email address is natzjordaan@gmail.com

I hate to disturb you but thanks for your patience! Thank you very much, again!

 


Posted: 7/6/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

I wonder how are you passing values of order and description which you set at page load to your click event. You can go like this:

    private string order { get; set; }
    private string description { get; set; }
     
    protected void Page_Load(object sender, EventArgs e)
    {
        order = Request.Form["order"];
        description = Request.Form["description"];
    }


and then use them in your click event. 

 


Posted: 7/6/2011

Lurker 55  points  Lurker
  • Joined on: 7/5/2011
  • Posts: 11

Yay thank you it is working but one select tag is not working. It is too close to be fixed :-D I have been exploring and found something.

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

Name: Natalie
Surname: Jordaan
Email: cyberoxy@lantic.net

Description:Card A6 // displaying data yay it is working :-D
 

Order:true   // no data

        msg += "<br>Description:" + description.Value; //it is correct
        msg += "<br>Order:" + group1.Visible;// it is wrong. replace something with Visible??
I have put runat="server" in optgroup tag instead of select tag- seems working because there is no displaying compile error

<select name="order" multiple="multiple" size="12" style="width:330px;" id="dlist1" onchange="swapImage1()">
        <optgroup label="Sow Seeds of Love" id="group1" runat="server">
            <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>

Posted: 7/6/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Is your problem resolved or not can you be specific what is not resolved?


Posted: 7/6/2011

Lurker 55  points  Lurker
  • Joined on: 7/5/2011
  • Posts: 11

Seem you dont get my other message. I resend it:

Yes the one problem (description) is resolved.  Yay thank you very much! But one select tag is not working. It is too close to be fixed :-D I have been exploring and found something.

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

Name: xxx
Surname: xxx
Email: xxxxx

Description:Card A6 // displaying data yay it is working :-D

 Order:true   // no data

It should be : Order: Images/order_names/faithcard.jpg

code behind:

        msg += "<br>Description:" + description.Value; //it is correct
        msg += "<br>Order:" + group1.Visible;// it is wrong. replace something with Visible??
I have put runat="server" in optgroup tag instead of select tag- seems 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" id="group1" runat="server">
            <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>
You can see it is almost resolved. Phew! I am just asking what must I replace with Visible because it only displays true in email ?

Posted: 7/6/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

With the below code I am getting order as "Images/Order_names/SowSeeds/Grace01_green.jpg"

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <select name="order" multiple="multiple" id="dlist1" 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 Card</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 Card</option>
        </optgroup>
        <optgroup label="Goosebumps Vintage A">
            <option data-card="32.00" data-memo="62.00" data-tags1="1.80" data-tags4="----" data-key="30.00"
                data-fridge="40.00" data-flower_sachet="----" value="Images/Order_names/GoosebVA/GoosebumpVA_blue.jpg">
                Blue</option>
        </optgroup>
    </select>
    <table>
        <tr>
            <td class="style3">
                <input type="checkbox" name="description" value="Card A6" id="description" />
                Card A6 (blank)
            </td>
        </tr>
    </table>
    <asp:Button ID="SubmitButton" runat="server" Text="Button" />
    </form>
</body>
</html>

<script runat="server">

    private string order { get; set; }
    private string description { get; set; }
     
    protected void Page_Load(object sender, EventArgs e)
    {
        order = Request.Form["order"];
        description = Request.Form["description"];
    }
</script>



Posted: 7/6/2011

Lurker 55  points  Lurker
  • Joined on: 7/5/2011
  • Posts: 11

Dear Raghav, I have used your code script in markup but it keeps displaying compile error so I tried another way to solve it and it is working but I am just asking you what must I replace witth Visible to display data such as "Images/Order_names/SowSeed/Grace01_green.jpg" instead of displaying "true"?

Email in my gmail account:

 Order:true   // no data - how can I display full data "Images/Order_names/SowSeed/Grace01_green.jpg"??

Please review my codes below:

code behind:

        msg += "<br>Description:" + description.Value; //it is correct
        msg += "<br>Order:" + group1.Visible;// it only display "true". I need full data. what must i replace with Visible? It is just small problem i need to resolve :-)
I have put runat="server" in optgroup tag instead of select tag- seems 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" id="group1" runat="server"> // it seems working
            <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>


Posted: 7/6/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Show me your full markup which you have right now.


Posted: 7/6/2011

Lurker 55  points  Lurker
  • Joined on: 7/5/2011
  • Posts: 11

Okay I copy both markup and code behind:

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" id="group" runat="server"> //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
{
  //  private string order { get; set; }
   // private string description { get; set; }

    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");
    }
}


Page 1 of 1 (16 items)