ccNewsletter

Topics: Controls
Jun 9, 2009 at 6:46 PM

Hi, I'm trying to make something like ccNewsletter from Joomla for BE.

So, I did some editing, copy and pasting from Pages.aspx and come up with something like this...

 

Free Image Hosting at www.ImageShack.us

 

My problem is, when I hit the Delete link, this is what I get

 

Free Image Hosting at www.ImageShack.us

 

So far this is my code behind file coz I'm already stuck with this problem.


public partial class admin_Pages_newsletter : System.Web.UI.Page
{
    private static string connString = ConfigurationManager.ConnectionStrings["BlogEngine"].ConnectionString;
    private static DbProviderFactory provider = DbProviderFactories.GetFactory(ConfigurationManager.ConnectionStrings["BlogEngine"].ProviderName);


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            if (!String.IsNullOrEmpty(Request.QueryString["id"]))
            {
               
               

            }
            else if (!String.IsNullOrEmpty(Request.QueryString["delete"]))
            {
               
                DeleteNewsletter(Convert.Int32(Request.QueryString["delete"]));
            }

            Page.Title = "Newsletter";
            BindNewsletterList();
        }
    }


    #region  Newsletter

    private void DeleteNewsletter(int id)
    {

        if (id != null)
        {
            //try
            //{
                using (DbConnection conn = provider.CreateConnection())
                {
                    conn.ConnectionString = connString;
                    using (DbCommand cmd = conn.CreateCommand())
                    {
                        string sqlQuery = "DELETE FROM be_newsletter_newsletters WHERE id=@id";
                        cmd.CommandText = sqlQuery;
                        cmd.CommandType = CommandType.Text;
                       
                        DbParameter dpId = provider.CreateParameter();
                        dpId.ParameterName = "@id";
                        dpId.Value = id;
                        cmd.Parameters.Add(dpId);

                        cmd.ExecuteNonQuery();

                        conn.Close();

                    }
                }
            //}
            //catch
            //{
                //Response.Redirect("pages.aspx");
            //}

            Response.Redirect("newsletter.aspx");
        }
    }

    #endregion


    #region data binding

    protected void BindNewsletterList()
    {
        int count = 0;
        try
        {
            using (DbConnection conn = provider.CreateConnection())
            {
                conn.ConnectionString = connString;
                using (DbCommand cmd = conn.CreateCommand())
                {
                    string sqlQuery = "SELECT id,name FROM be_newsletter_newsletters";
                    cmd.CommandText = sqlQuery;

                    conn.Open();

                    using (DbDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            if (rdr.HasRows)
                            {
                                HtmlGenericControl li = new HtmlGenericControl("li");
                                HtmlAnchor a = new HtmlAnchor();
                                a.HRef = "?id=" + rdr.GetInt32(0);
                                a.InnerHtml = rdr.GetString(1);

                                System.Web.UI.LiteralControl text = new System.Web.UI.LiteralControl
                                ("  ");

                                string deleteText = "Are you sure you want to delete the page?";
                                HtmlAnchor delete = new HtmlAnchor();
                                delete.InnerText = "-Delete-";
                                delete.Attributes["onclick"] = "if (confirm('" + deleteText + "')){location.href='?delete=" + rdr.GetInt32(0) + "'}";
                                delete.HRef = "javascript:void(0);";
                                delete.Style.Add(System.Web.UI.HtmlTextWriterStyle.FontWeight, "normal");

                                li.Controls.Add(a);
                                li.Controls.Add(text);
                                li.Controls.Add(delete);
                                li.Attributes.CssStyle.Remove("font-weight");
                                li.Attributes.CssStyle.Add("font-weight", "bold");

                                ulPages.Controls.Add(li);
                                count = rdr.FieldCount;
                            }
                        }
                    }
                    conn.Close();
                }
            }
        }
        catch
        {
            //return null;
        }

            divPages.Visible = true;
            aPages.InnerHtml = count + " Newsletters";
       
    }


    #endregion
}

 

Thanks!

Jun 10, 2009 at 6:25 PM

anyone?

Jun 10, 2009 at 11:36 PM

I can't see that image real clear, is that a language besides English, or just some rubbish?

 

If it is a language besides English, can you post the English version?

Jun 11, 2009 at 7:16 AM
Edited Jun 11, 2009 at 7:19 AM

no. this is what happen when i tried to hit delete.  it is not suppose to show those funny writings. just rubbish! i dont know why

Jun 13, 2009 at 10:13 PM

I have some spare time from Wednesday onwards - so will help you debug this issue if you want - can you post the files in their entirty or better still email them to me at davidmiles@spamarrest.com and I will help you out

David

Coordinator
Jun 14, 2009 at 7:22 AM

To get an actual error message, rather than that garbarge, add the code I posted in this discussion on April 23rd to your global.asax file.

Jun 14, 2009 at 10:21 AM
Edited Jun 14, 2009 at 10:22 AM

Thanks Ben! Now i can read the error message.