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. Advertisements

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. titof
    Replies:
    0
    Views:
    710
    titof
    Jul 24, 2003
  2. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,323
    Lau Lei Cheong
    May 15, 2004
  3. nail
    Replies:
    0
    Views:
    1,728
  4. E11
    Replies:
    1
    Views:
    5,665
    Thomas Weidenfeller
    Oct 12, 2005
  5. Pedro Martins
    Replies:
    2
    Views:
    2,429
    Roedy Green
    Feb 24, 2006
  6. Replies:
    0
    Views:
    623
  7. Glenn Gillen
    Replies:
    0
    Views:
    486
    Glenn Gillen
    Nov 17, 2006
  8. ASD
    Replies:
    2
    Views:
    143
    Thomas 'PointedEars' Lahn
    Nov 24, 2003
Loading...