Hey there!

Im developing website using asp.net c# but Im using some html tags in asp.net c# mixed.

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

Contact.aspx:

[B]<select[/B] name="order" multiple="multiple" id="dlist1" onchange="swapImage1()">
        [B]<optgroup[/B] label="Sow Seeds of Love">
            [B]<option [/B]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[B]</option>[/B]
            [B]<option[/B] 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[B]</option>     
       [B] <optgroup>[/B][/B]
        [B]<optgroup[/B] label="Goosebumps Vintage A">
           [B] <option[/B] 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[B]</option>[/B]
       [B] </optgroup>[/B]

[B]</select>[/B]

[B]<table>[/B]

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

[B]</table>
[/B]

<b><u></u>Contact.aspx.cs:</b>

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

          msg += "&lt;br&gt;Description:" + 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!

Member Avatar for stbuchok

I believe all you need to do is add the runat="server" attribute.

<select name="order" multiple="multiple" id="dlist1" onchange="swapImage1()" runat="server">

Hope it works.

Hey stbuchok

Thanks for your reply. Appreciate it! I followed your suggestion. I put runat="server" but 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'.

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

Look my codes below:

protected void Send_Click(object sender, EventArgs e)
    {

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

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

        var order = Request.Form["order"]; 
        var description = Request.Form["description"]; //I also have tried to move this 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 several ways to solve it but still not this data in email. Strange! Thanks for your time :-)

Appreciate your help!

Member Avatar for stbuchok

Apparently this is supposed to be due to the optgroup tag. Can you not use the <asp:Dropdownlist> server control?

Member Avatar for stbuchok
<asp:Dropdownlist runat="server" ... />

Yes I know I should use dropdownlist instead but I know how to implement html control. I have been exploring and trying several times how it works and now I found something but I need to know what must I replace with this Visible (read below)?

You know I wrote codes in code behind (c#) to make accessible data to my gmail account. I got the email from gmail account after clicking send email button - look at the data (bold):

Name: xxx
Surname: xxx
Email: xxxxx
Description:Card A6

Order:true // no data -- It should be : Order: Images/Order_names/SowSeeds/Faith01_yellow.jpg


code behind:

msg += "<br>Description:" + description.Value; //it is correct
        msg += "<br>Order:" + group1.Visible;// it only display "true" but i need it to display full data such as "Images/Order_names/SowSeeds/Faith01_yellow.jpg" in my email. So I am asking what must I replace with this Visible to display full data in email?

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="----" [B]value="Images/Order_names/SowSeeds/Faith01_yellow.jpg"[/B]>Faith</option>
</optgroup>

I am just asking what must I replace with Visible because it only displays true in email? I just post a new threat "need small fixing"

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.