Render UserControl in Class wihtout access to webform?

Discussion in 'ASP .Net' started by =?Utf-8?B?RGFuaWVsIERpIFZpdGE=?=, Aug 1, 2007.

  1. I need to render a user control as a HTML string. I do not want the control
    to appear on the page, however. Here is what I am doing…
    I have an HTML template that will ultimately be sent via e-mail. Inside the
    template I have IDs setup for each section that will be replaced with dynamic
    data. In one section I need to display a specific kind of data. I already
    have a user control that generates what I need. I need to get that control to
    fire and then get rendered as HTML to be placed in the appropriate section of
    the fore mentioned HTML template. This is the code I have so far:

    Private Function BuildPropertyDetialsInfo() As String
    Dim propertyInfoControl As New StringBuilder
    Dim propertyInfoUserControl As New UserControl
    Dim propertyInfoStringWriter As New StringWriter(propertyInfoControl)
    Dim propertyInfoHTMLWriter As New
    HtmlTextWriter(propertyInfoStringWriter)

    Try
    propertyInfoUserControl.LoadControl(propertyDetialsInfoPath)

    propertyInfoUserControl.RenderControl(propertyInfoHTMLWriter)
    Catch ex As Exception
    End Try
    Return propertyInfoControl.ToString
    End Function
    I donl’t get anything back. I am assuming that I need to add the control to
    the collection, but I don’t know how I would do this since I am not working
    on a web form. I am inside a class that doens’t have access to a form page.
    Any thoughts?

    Daniel
    =?Utf-8?B?RGFuaWVsIERpIFZpdGE=?=, Aug 1, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,065
    Lau Lei Cheong
    May 15, 2004
  2. nail
    Replies:
    0
    Views:
    1,539
  3. Pedro Martins
    Replies:
    2
    Views:
    2,133
    Roedy Green
    Feb 24, 2006
  4. Glenn Gillen
    Replies:
    0
    Views:
    274
    Glenn Gillen
    Nov 17, 2006
  5. ASD
    Replies:
    2
    Views:
    72
    Thomas 'PointedEars' Lahn
    Nov 24, 2003
Loading...

Share This Page