Asp.Net Class - problem returning html string value
<p>I'm trying to get my class to return a html string which I then assign to a control on a aspx page as: this.div1.InnerHtml =  class.News();</p>

<p>However, my catch code is always firing, returning my 'NoValue' message.</p>

<p>The code works fine outside of the class. </p>

<p>When I comment out the reader lines htmlStr.Append(reader["Title"].ToString()); I can get the string back to my calling code, is there something else I need to do, to use readers in classes?</p>

<p>namespace confonline
{</p>

<pre><code>public class conf
{
    private string connectionStringBMP = WebConfigurationManager.ConnectionStrings["ConfBMP"].ConnectionString;

    public string News()
    {

        SqlConnection conn = new SqlConnection(connectionStringBMP);
        SqlCommand cmd = new SqlCommand("spNews ", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@number",2);

        SqlDataReader reader;

        try
        {
            conn.Open();

            reader = cmd.ExecuteReader();
            StringBuilder htmlStr = new StringBuilder("");

            while (reader.Read())
            {
               htmlStr.Append("&lt;div class='news'&gt;");
                htmlStr.Append("&lt;img align='left' title='" + reader["ThumbnailText"].ToString() + "' alt='" + reader["ThumbnailText"].ToString() + "' src='images/news/thumbnails/" + reader["PublishYear"].ToString() + "/" + reader["Photo"].ToString() + "'&gt;");
                htmlStr.Append("&lt;a href=news.aspx?p=" + reader["ID"] + "&gt;");
                htmlStr.Append(reader["Title"].ToString());
                htmlStr.Append("&lt;/a&gt;");
                htmlStr.Append("&lt;/div&gt;");
            }

             string htmlString = htmlStr.ToString();

             reader.Close();

             return htmlString;

        }
        catch (Exception err)
        {
            HttpContext.Current.Response.Write(err.Message);
            string noVal = "No Value";
            return noVal;

        }
        finally
        {
            conn.Close();
        }

    }
}
</code></pre>

<p>}</p>
