Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Getting HTML result of Custom User Control for use in an email

Getting HTML result of Custom User Control for use in an email

Scheduled Pinned Locked Moved ASP.NET
csharphtmlasp-netcom
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Justin Porteous
    wrote on last edited by
    #1

    Good day fellow CodeProject.com'ers, I have an ASP.NET (C#) Base application which I would like to take the result of a custom user control, and use the resulting HTML from the control (or many multiple controls) as the body in an email. Any ideas?

    J - Artificial intelligence is no match for natural stupidity

    N J 2 Replies Last reply
    0
    • J Justin Porteous

      Good day fellow CodeProject.com'ers, I have an ASP.NET (C#) Base application which I would like to take the result of a custom user control, and use the resulting HTML from the control (or many multiple controls) as the body in an email. Any ideas?

      J - Artificial intelligence is no match for natural stupidity

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      This[^] should do the trick.

      Navaneeth How to use google | Ask smart questions

      J 2 Replies Last reply
      0
      • J Justin Porteous

        Good day fellow CodeProject.com'ers, I have an ASP.NET (C#) Base application which I would like to take the result of a custom user control, and use the resulting HTML from the control (or many multiple controls) as the body in an email. Any ideas?

        J - Artificial intelligence is no match for natural stupidity

        J Offline
        J Offline
        Justin Porteous
        wrote on last edited by
        #3

        After posting this I decided to play a little more, and I think I got it, hope this helps someone... I created a user control in the folder "Controls" called "WebUserControl.ascx". I decided if I could write the control programatically to the page, I could then use that variable later for the email section. Here is the code I came up with... if anyone can better it, please post here:

        using System;
        using System.Configuration;
        using System.Data;
        using System.Web;
        using System.Web.Security;
        using System.Web.UI;
        using System.Web.UI.HtmlControls;
        using System.Web.UI.WebControls;
        using System.Web.UI.WebControls.WebParts;
        using System.Text;
        using System.IO;

        public partial class _Default : System.Web.UI.Page
        {
        protected void Page_Load(object sender, EventArgs e)
        {
        System.Text.StringBuilder stringBuilder = new StringBuilder();
        StringWriter stringWriter;
        HtmlTextWriter htmlTextWriter;
        stringWriter = new System.IO.StringWriter(stringBuilder);
        htmlTextWriter = new HtmlTextWriter(stringWriter);

            Control c1 = LoadControl("Controls/WebUserControl.ascx");
            c1.DataBind();
        
            c1.RenderControl(htmlTextWriter);
            Response.Write (htmlTextWriter.InnerWriter.ToString());
        
        }
        

        }

        J - Artificial intelligence is no match for natural stupidity

        1 Reply Last reply
        0
        • N N a v a n e e t h

          This[^] should do the trick.

          Navaneeth How to use google | Ask smart questions

          J Offline
          J Offline
          Justin Porteous
          wrote on last edited by
          #4

          Thanks, I saw your post just after I posted my last one, I will check it out...

          J - Artificial intelligence is no match for natural stupidity

          1 Reply Last reply
          0
          • N N a v a n e e t h

            This[^] should do the trick.

            Navaneeth How to use google | Ask smart questions

            J Offline
            J Offline
            Justin Porteous
            wrote on last edited by
            #5

            That's a good link, thank you!

            J - Artificial intelligence is no match for natural stupidity

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups