Introducing ElegantBlue theme for BlogEngine

Posted by Mohammad Mahdi Ramezanpour on Comments (2)

It’s about six years I’m blogging my life and using BlogEngineto publish my posts; because I believe it’s the best blog engine ever. As a matter of fact, BlogEngine is doing everything I need as a blogger and sometimes more than that. I highly recommend using it if you’re blogger!

But this post is not about BlogEngine itself! In this post I’m going to introduce a new theme for BlogEngine which is so cool!

Note: If you don’t know BlogEngine yet, please check out its website at: http://dotnetblogengine.net.

It was about five months I was going to change my blog’s theme to a new one that includes latest web standards such as HTML5 and CSS3 but I didn’t have time for that. Yesterday, I decided to change my blog theme and it took about 12 hours to create a new one. In fact, I didn’t create the theme from scratch! ElegantBlue Theme

The ELEGANTBLUE Theme

ElegantBlue originally designed by freecsstemplates.organd I’ve changed it a lot to get it compatible with BlogEngine. Here’s the list of things I’ve changed:

HTML5 & CSS3

Everybody is talking about HTML5 and CSS3 these because it’s awesome! It’s about a year that I’m using these in my projects. HTML5 and CSS3 give me lots of capabilities I didn’t have before and help me create user-interfaces like never before. Also, they help search engines to index your website faster than before! For example, with the new <header> HTML5 tag, search engines can recognize where your website’s header is. The ElegantBlue theme for BlogEngine is a HTML5 and CSS3 theme so search engines can find your blog contents faster and the user interface is much cooler!

Razor View Engine

In BlogEngine 2.5, you can create themes and extensions using Razor view engine. Here’s a brief explanation about Razor:

The Razor syntax is a template markup syntax that enables the programmer to use an HTML construction workflow and is based on the C# programming language. Instead of using the ASP.NET .ASPX markup syntax using <%= %> blocks to indicate code blocks the Razor syntax starts of a code block with Razor using a @ character and does not require explicit closing of the code-block.

I totally used Razor view engine in ElegentBlue theme for BlogEngine.

Note: In order to implement Razor view engine, BlogEngine has RazorHost directory in the theme folder of the application. RazorHost folder is like a default template for Razor themes. If you’re going to use this theme in your website, you need to change the DOCTYPE to HTML5 in “site.master” file because it’s set to XHTML 1.0 by default. Besides, I include this change in the download file at the end of this post.

Download

You can download the theme right from here.

 ElegantBlue.zip (352.05 kb)

Hope it helps.

Introducing an awesome asyc file uploader, “ManageMedia”

Posted by Mohammad Mahdi Ramezanpour on Comments (4)

Yesterday, one of my best friends, Omid Mafakher, called and told me about one of his project which he’s working on for a while and as I checked it out, realized that this is so cool so I decided to share it with you too.

I know there are some Asyc File Uploaders available right now like AjaxControlTookit.AsycUploader and such but this control is something different! Actually, you may have seen such a thing on a few websites like Google and Facebook!

ManageMedia Snapshot

Besides, there are lots of useful features in this library as well like image resizing, watermark, background and foreground settings, etc.

Here’s the list of key features:

  • Upload file up to any size in .NET.
  • Validate the file (size, type) before uploading.
  • Upload with progress (Size, Speed, Time, Total Size, etc.)
  • Upload to temp file during upload.
  • Save uploaded file with too many configurations.
  • Manage the Image file and save in any format (PNG, JPG, GIF, BMP, etc.)
  • Save image in any size.
  • Resizing styles: "Center, Tile, Stretch, Zoom, CenterIfNoZoom, Corp (Facebook style)".
  • Set the Background and Foreground in your image.
  • Change the image Alpha and Resolution.
  • HttpHandler for generating images.
  • HttpModule for generating unsaved or deleted images.
  • web.config Section for Multiple settings to save file and image.
  • web.config Section to manage HttpHandler and HttpModule.

Fortunately, my friend has published it in CodePlex as an open source project so you can enjoy using it for free! You can click the link below to access and download this library from CodePlex:

http://managemedia.codeplex.com/

I highly recommend you to check this out! And comment your feedback here or in its official CodePlex page.

Hope you like it.

Implementation of HTML 5 number input in ASP.NET web forms

Posted by Mohammad Mahdi Ramezanpour on Comments (5)

As I mentioned in my previous post, HTML 5 and CSS 3 are rocking and most of web developers are trying to upgrade their project to HTML5 because it makes their life easier and Microsoft has done a great job by adding HTML5 intellisense to Visual Studio 2010 SP1.

Everything works great in ASP.NET MVC and ASP.NET Web Pages project but when it comes to ASP.NET web forms, you may have some problems using HTML5 tags in your application and access them from runtime. You can’t use the following:

<input type="number" runat="server" />

Yesterday, I was trying to use HTML5 number input tag in my application and found out that ASP.NET web forms engine doesn’t support HTML5 new elements so I decided to write my own NumberTextBox control in order to do so and in this post I’m going to share it with you.

As you know, when want to develop an ASP.NET custom server control, you have to inherit your control’s class to System.Web.UI.WebControls.WebControl; and in this case, I implemented IPostBackDataHandler because it’s a necessary interface when your control is going to process during post backs.

public class NumberTextBox : WebControl, IPostBackDataHandler

The second is to add a “Value” property to the class in order to get and set the value of control which is very easy task to do.

public int Value
{
    get
    {
        if (Page.IsPostBack)
        {
            try
            {
                ViewState["Value"] = Page.Request.Form[this.UniqueID];
            }
            catch { ViewState["Value"] = 0; }
            return Convert.ToInt32(Page.Request.Form[this.UniqueID]);
        }
        if (ViewState["Value"] == null) return 0;
        return (int)ViewState["Value"];
    }
    set { ViewState["Value"] = value; }
}

There are a few things to consider while adding the value property:

  • The property must return value from Page.Request.Form[“Control ID”] because all HTML controls send data via HTTP headers (or QueryString) in Postbacks; so the only way to get the value which is entered by user in post back is using Page.Request.Form[“Control ID”].
  • You should use ViewState in order save the current value of control over posts backs. It’s very common among Visual Studio Controls. As I checked, TextBox control is also use this way to save that data. The third is the implementation of IPostBackDataHandler:
    public event EventHandler TextChanged;
    
    public bool LoadPostData(string postDataKey, 
    System.Collections.Specialized.NameValueCollection postCollection)
    {
        string currentValue = this.Value.ToString();
        string postedValue = postCollection[postDataKey];
        if (currentValue == null && !currentValue.Equals(postedValue))
        {
            this.Value = Convert.ToInt32(postedValue);
            return true;
        }
        else
            return false;
    }
    
    public void RaisePostDataChangedEvent()
    {
        OnTextChanged(EventArgs.Empty);
    }
    
    public virtual void OnTextChanged(EventArgs e)
    {
        if (TextChanged != null)
            TextChanged(this, e);
    }

    The last thing to do is to render the control:

    protected override void RenderContents(System.Web.UI.HtmlTextWriter w)
    {
        w.Write(
            "<input type=\"number\" id=\"{0}\" name=\"{0}\" value=\"{1}\" />", 
            this.UniqueID, this.Value.ToString());
    }

    As you can see I use HTML5 features.

    Now you can add your custom server control to your application:

    <cc1:NumberTextBox ID="NumberTextBox1" runat="server" />
    And the result would be something like this:
    HTML5 number
    By the time, Only Opera and Google Chrome supports up/down arrows functionalities and I really recommend to use Modernizr to make your web app work fine on all browsers.

I also send the source code of this control to help you out. The only thing you need to do is to add this to your project and enjoy:

NumberTextBox.cs (2.02 kb)