2

I have a div tablePrint in aspx page. I want to get all elements of this div in my web service. Actually I have to send email from my service that has a html body so I want to send tablePrint as email body. I have no idea how to get elements of tablePrint in my web service. How can I do this?

 <div class="pagecontent2"> 
                <asp:Panel ID="pnl" runat="server">
        <div id="tablePrint">
                <div style="BORDER-BOTTOM: #dfdfdf 3px solid; PADDING-BOTTOM: 1px; MARGIN-BOTTOM: 10px; HEIGHT: 25px;">
                <div style="FLOAT: left; COLOR: #007ec6; FONT-SIZE: 18px; VERTICAL-ALIGN: bottom; FONT-WEIGHT: bold; PADDING-TOP: 5px; padding-left:10px;">
                    <div style="float: left;">
                        CompanyName
                    </div>
                    <div style="float: left; padding: 5px 0 0 200px;">
                    </div>
                </div>
                <div style="TEXT-ALIGN: right; FLOAT: right">
                    <div style="color:gray;padding-top:8px;padding-right:5px;">Receipt</div>
                </div>
                <div class="clear">
                </div>
            </div>....
yakhtarali
  • 432
  • 13
  • 30
  • 1
    You make get the div with javacript, use the innerHtml, to read the content, and send it to server. – Aristos Jan 28 '14 at 07:36

2 Answers2

2

Pass it like this

JSON.stringify({'num':HTML});

You have to stringify the content to JSON properly. HTML may contain synataxes that would make the JSON notation invalid.

  var dataToSend = JSON.stringify({'num':HTML});
         $.ajax({ url: "EditingTextarea.aspx/GetValue",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: dataToSend , // pass that text to the server as a correct JSON String
                success: function (msg) { alert(msg.d); },
                error: function (type) { alert("ERROR!!" + type.responseText); }

            });
0

First way, if you don't konw ajax, put an asp textbox, an asp button and any html button, put on html button's click event:

document.getElementById('TextBox1').value = document.getElementById('tablePrint').innerHTML;
aspButton.click();

Then assign your mails body part your in server side

mailMessage.Body = TextBox1.Text;

and send mail. But you must set your validation in your page as

ValidateRequest = "false"

and in your Web.config file

<httpRuntime requestValidationMode="2.0" />

Second way, if you know ajax, send your div's innerHTML to server. For this, follow link

Community
  • 1
  • 1
Metehan Teber
  • 194
  • 2
  • 5