• HELP! SQL Session State in ASP.net 2.0

    I am having huge problems with setting up SQL session state for my ASP.net app.  I have run the aspnet_regsql.exe tool and the database has been created correctly with the user id etc.However nothing is saved in the session...i can look at the sql tables and see that in the TempApps table i have my application, when i look in the TempSession table i don't have any rows.

    I have tried to do something very simple like this...

    Master.PageTitle is just the text property of a label control.

    if (Session["test"] != null)

       Master.PageTitle = Session["test"].ToString();

    else {

       Session["test"] = "Hello from SQL session";

       Master.PageTitle = "Yes i am null";



    Master.PageTitle += Session["test"].ToString();

    The property is always "Yes i am nullHello from SQL session"

    So the Session is set but when i postback to the server again the session is null.???The exact same code works in InProc mode, and so does the rest of my Session management code.I am normally storing an object which i have set as [Serializable]

    In my web.config i have


    sqlConnectionString="user id=<userid>; password=<password>; data source=server1;"

    cookieless="AutoDetect" />

    Is there something i am missing?? I have followed the msdn to the T, just seems like i am missing something?




    I found this issue the other day....I was trying to serialize a DataView object...doh!


  • N-tier or N-layer ASP.net 2.0

    Recently found some great tutorials on n-tier development with asp.net 2.0, well actually its n-layer to me.  I consider n-tier development to be across different hardware platforms e.g. database server, presentation server (front end or presentation layer).  N-layer development is separating your application code into layers... presentation layer, business logic layer, data access layer and data layer. 

    Most of the time you will develop on 2-tiers as above, having a database server is quite normal practice.

    I have never actually developed an n-tier application but i have heard that its a nightmare....n-layer on the other hand I am a fan off and asp.net 2.0 makes it very easy to do.  The idea of having your code separated into loosely coupled layers is a fantastic idea, makes it very easy to read and maintain your code.  I recently finished a big web app and developed in n-layer architecture and found these articles very helpful.  Hopefully you will too.

    Check out these four articles by Scott Mitchell, he is the founder of www.4guysfromrolla.com (a great source for tutorials) you can read his blog at http://scottonwriting.net

    1. Creating a data access layer

    2. Creating a Business logic layer

    3. Master Pages and site navigation

    4. Displaying data with the ObjectDataSource from you BLL


  • Simple Atlas Tab Control

    I love using a nice little tab control on my web pages but I never seem to find an good solution…well a FREE (!) one anyway! There are some great tab controls out there to buy but I have never really looked at them as paying for controls is not in my vocabulary. This little control is probably no match for one of those but for a simple and FREE solution look no further! The problem I have with the current solutions I use are 1. The javascript and CSS solution using relative positioning and the visibility style attribute has the advantage of being nice for the user to use but depending on the number of tabs and what is on the tab it’s a pretty big overhead on the page to have all tabs there….just hidden. 2. asp.net has a great control called the Multiview control, which only renders the active view of this control, keeping the size of the page to a minimum but with the problem of a full page postback. Which for a tab control is pretty not a nice experience. So we merge the Atlas update panel with the asp.net 2.0 Multiview control, some HTML tables and we have a nice tab control. There are limitations to this control, one being that the tabs have to added to the .ascx file HTML markup manually. The Code The tab control is contained within a .ascx files, which encapsulates the markup, script and properties for the control.The tabs are simple done using CSS, HTML and Javascript(just to give a little hover affect).

    <div id="tabs" style ="text-align: left; padding: 4px 0px 0px 0px; color: Black;">

            < table cellspacing="0" cellpadding="0" style="width: 100%">


                    <td class="spacer">


                    <tdclass="tabactive"id="tab1"onmouseover="return tab_OnMouseOver(this)"onmouseout="return tab_OnMouseOut(this);">


                        <asp:LinkButtonCssClass="tabbtn"runat="server"ID="btnTab1"Width="90"OnClientClick="return tab_activate('tab1');"

                            CommandArgument="0" OnCommand="btnTabs_Command"<asp:LinkButton>


    The content section of the tab control is an updatepanel with the MultiView control inside.

    <div id="content"style="margin: 10px 2px 2px 2px; text-align: left; color: Black;

            overflow: auto; height: 100%; width: 100%;">







    I have used the ITemplate interface for the content of each tab, the may be new to some people so take a look at the code and download the project for a better look.

    privateITemplate _view1;


    [PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(TemplateControl))]

    publicITemplate Tab1


        get { return _view1; }

        set { _view1 = value; }}


    Each tab has a link button and the Text property is exposed. 

    #region Link Button Text Property Accessors


        publicstring Tab1Title


            get { return btnTab1.Text; }

            set { btnTab1.Text = value; }


    The Link button Command event is handled, this is tidyer than using 5 click events, i have set the commandargument of each button to the tab number.

    This event is sent to the calling webform as a new event for this control...TabChanged, which also has the CammandEventArgs as a parameter, this enables you to perform tab spefic binding for a each of the tabs on the webform.

    // Delegate to represent TabChanged event signature.

    publicdelegatevoidTabChangedEventHandler(object sender, CommandEventArgs e);


    // Event using the above handler.

    publiceventTabChangedEventHandler TabChanged;


    #region Tab Command


    protectedvoid btnTabs_Command(object sender, CommandEventArgs e)


        // Change ActiveViewIndex for MulitView control.

        MultiViewContent.ActiveViewIndex = Convert.ToInt32(e.CommandArgument);


        if (TabChanged != null) {

            // TabChanged..send event to calling webform.

            TabChanged(this, e);





    On the calling webform handle the TabChanged event and perform specific tab actions to do whatever is required.  In this example you can see i have a GridView on tab 5 that i only bind when tab 5 is selected

    // Event handler for tabs changed

    protected void TabsView1_OnTabChanged(object sender, CommandEventArgs e)


         switch (Convert.ToInt32(e.CommandArgument)) {


         case 0:

               Label lbl = (Label)TabsView1.Tab1Controls.FindControl("label2");

               lbl.Text = e.CommandArgument.ToString();


         case 4:






    void BindGridOnTab5()


        System.Collections.ArrayList al = new System.Collections.ArrayList();

        al.Add(newListItem("Steve Clements Blog", "http://geekswithblogs.net/steveclements"));

        al.Add(newListItem("asp.net", "http://www.asp.net"));

        al.Add(newListItem("Atlas", "http://atlas.asp.net"));


        GridView grid = (GridView)TabsView1.Tab5Controls.FindControl("grdTab5");

        if (grid != null) {

            grid.DataSource = al;




    Finished article look a little like this....


    Download the code from here.

    Hopefully you have learnt a few things from this post, and enjoy playing/enhancing this simple control for your own pages.



  • Live Writer Test

    I got the specified cast error that Azam had trying to edit a post so thought i would try a new one.

    Here goes



  • Visual Studio 2005 Fonts Pack.

    Just found this today. A fonts pack for VS 2005, changes the default font to Consolas, in my opinion much better to look at...its a pretty smooth font compared to Courier without going all the way to Arial. Those who have used Office 2007 beta2 will recognise it. MS Font Pack Steve


  • First MCP - woohoo

    Just passed my first MCP exam, developing and implementing windows app in C#. Been studying pretty hard for about 10 days so chuffed to pass with 90% especially seeing Win apps is my weaker area :) that'll come back and bite me in the ass if i fail web apps!!! ;-) which is next. Rewarded myself with a nice MS logo on my blog and CV!!! Might even have a few beers tonight!!!


  • Hello - My introduction

    Hi there, thought I would post a little intro blog to introduce myself to anyone reading this blog. I am in England in the south west county of Somerset. The main point of my blog will be to post interesting tutorials and articles on .NET v2, always C#, lots of asp.net with a little bit of SQL slipped in. You may also find a few blogs on something interesting (to me!) that I have done in the recent past…..basically this will turn into my Brain dump, hopefully some good stuff in between one or two rambles! ;-) I work as a C# solutions developer mainly doing web stuff. My main interest at the moment revolves around ‘Atlas’, I don’t know a great deal Javascript so I find working and extending Atlas great fun. The Toolkit is equally as interesting…you can find the Atlas Control Toolkit on codeplex. The non developer in me (not much!) is a sports fan, I support Liverpool football club. I play cricket on a weekend for a local team. I don’t play football because I simply aint fit enough….too much sitting on my bum at my pc. Lived with my girlfriend (Kim) for 7 years, she is a fitness fanatic and works for a sports and leisure company. I am a reasonably junior .NET developer, only been writing solutions for about 18 months. So to all you new developers out there I will be providing some great stuff to introduce you to some new stuff. I am always trying new ways to ‘code better’ and am really into best practice coding. Anyways…subscribe to my feed and keep an eye out for some interesting stuff.