Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (0)

This is the best tutorial for creating a database Layer DAL in Visual Studio 2005:

http://www.asp.net/learn/dataaccess/tutorial02cs.aspx?tabid=63

Shows you how to implement and use partial classes to create you own objects. Scott Michell is a great author.

After dragging and dropping the fields that you need, Visual Studio 2005 will create the public methods to DELETE, INSERT AND UPDATE.

Adding new queries is easy by using the UI. Each query will be created as a public method of the Adapter class. You can also use Transactions class if you need to queue many of them. If any of them failed, the system will roll them back.

This is the solution to complete Database Layer that everybody has been looking forward.

Cheers

Al

Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (0)

When adding an UpdatePanel inside a GridView or FormView you get the error that UpdatePanel cannot be placed inside a tempate.New Atlas release fixes the most annoying bug of all:

 

The UpdatePanel 'UpdatePanel1' was not present when the page's InitComplete event was raised. This is usually caused when an UpdatePanel is placed inside a template

 

Download ASP.NET “Atlas” June 2006 Community Technology Preview (CTP)

from here: http://www.microsoft.com/downloads/details.aspx?FamilyId=81BF1390-7894-4FF7-B591-1006BD770BC0&displaylang=en

 

I have not find any problem yet with this new release. There are many notes and helpful tips on http://atlas.asp.net as well and as always you can check Scott’s blog for any news about this fantastic library. http://weblogs.asp.net/scottgu/archive/2006/06/19/More-Atlas-Resources-_2800_Videos_2C00_-Articles_2C00_-WebCasts-and-Books_2900_.aspx

 

Best part, I can create my own controls: http://atlas.asp.net/atlastoolkit/Walkthrough/CreatingNewExtender.aspx

 

Cheers

Al

Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (4)

Once again after a year I found code for a windows service using System.Timers.Timer, and guess what, it does not work ... again ... duh. So after all these resources telling you, don't do it:

http://discuss.develop.com/archives/wa.exe?A2=ind0306D&L=DOTNET-CLR&P=R1007&D=0&I=-3

http://discuss.develop.com/archives/wa.exe?A2=ind0309D&L=DOTNET-CLR&P=R5347&I=-3

There are people that still use it for services. To all this people, please use System.Threading.Timer in 2.0 don't do it in 1.1. I believe there is still a bug assign to that one:

http://support.microsoft.com/?id=900822

Also, please rememeber that System.Threading.Timer  is not thread safe, even being on the Threading namespace is not thread safe, so real this awesome article from Alex Calvo for a safe service programming ;-)

http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/default.aspx

Hope this helps people to debug why their service stops calling the TimeElapsed function and why is not every X seconds.

Cheers

Al

Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (0)

Lately is you are using Visual Studio 2005, and of course if you have been writing code since 1.1 or even 1.0, you are used to use functions like:

 

RegisterStartupScript()

 

Well now you’ll get one of the warnings that are just giving me a headache:

This method is now obsolete.

 

Lets find out why? Just because there is an attribute to that method to produce the warning. I would like to know what that actually means?

 

[ObsoleteAttribute("The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202")] public virtual void RegisterStartupScript ( string key, string script )

 

http://msdn2.microsoft.com/en-us/library/system.web.ui.page.registerstartupscript.aspx

 

Does it mean that the guts are using old technology? Does it mean that they just wrapped around the function with the new one in order to move it somewhere else? Does it mean they won’t support it on version 3.0 so get used to use the new one? Does it mean they find a better way? If so, why there just left it in the namespace?

 

Anybody can let me know, why?

 

Cheers

Al

Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (4)

First add the Toolkit "AtlasControlToolkit.dll" by right clicking the ToolKit box and selecting Add Item.

That shall create and add all DLLs you need. Drag and drop any item into a webform to force Visual Studio 2005 to add the appropriate reference in the bin directory.

 

Changes on the web.config:

 

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

  <configSections>

    <sectionGroup name="microsoft.web" type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup">

      <section name="webServices" type="Microsoft.Web.Configuration.WebServicesSection" requirePermission="false"/>

    sectionGroup>

  configSections>

 

<microsoft.web>

    <webServices enableBrowserAccess="true" />

  microsoft.web>

 

 

Only once per page you need to add this tag. So if you are using master pages, this is where you want to add this:

 

<atlas:ScriptManager id="ScriptManager" EnablePartialRendering="true" runat="Server">atlas:ScriptManager>

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

All this will provide you with Atlas in any web project with ASP.NET 2.0 and Visual Studio 2005. Start playing with

<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional">

They are very powerful.

 

Cheers

Al

 

 

Only once per page you need to add this tag. So if you are using master pages, this is where you want to add this:

 

<atlas:ScriptManager id="ScriptManager" EnablePartialRendering="true" runat="Server">atlas:ScriptManager>

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

All this will provide you with Atlas in any web project with ASP.NET 2.0 and Visual Studio 2005. Start playing with

<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional">

They are very powerful.

 

Cheers

Al

 

<microsoft.web>

    <webServices enableBrowserAccess="true" />

  microsoft.web>

 

 

Only once per page you need to add this tag. So if you are using master pages, this is where you want to add this:

 

<atlas:ScriptManager id="ScriptManager" EnablePartialRendering="true" runat="Server">atlas:ScriptManager>

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

All this will provide you with Atlas in any web project with ASP.NET 2.0 and Visual Studio 2005. Start playing with

<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional">

They are very powerful.

 

Cheers

Al

 

 

Only once per page you need to add this tag. So if you are using master pages, this is where you want to add this:

 

<atlas:ScriptManager id="ScriptManager" EnablePartialRendering="true" runat="Server">atlas:ScriptManager>

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

All this will provide you with Atlas in any web project with ASP.NET 2.0 and Visual Studio 2005. Start playing with

<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional">

They are very powerful.

 

Cheers

Al

  configSections>

 

<microsoft.web>

    <webServices enableBrowserAccess="true" />

  microsoft.web>

 

 

Only once per page you need to add this tag. So if you are using master pages, this is where you want to add this:

 

<atlas:ScriptManager id="ScriptManager" EnablePartialRendering="true" runat="Server">atlas:ScriptManager>

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

All this will provide you with Atlas in any web project with ASP.NET 2.0 and Visual Studio 2005. Start playing with

<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional">

They are very powerful.

 

Cheers

Al

 

 

Only once per page you need to add this tag. So if you are using master pages, this is where you want to add this:

 

<atlas:ScriptManager id="ScriptManager" EnablePartialRendering="true" runat="Server">atlas:ScriptManager>

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

All this will provide you with Atlas in any web project with ASP.NET 2.0 and Visual Studio 2005. Start playing with

<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional">

They are very powerful.

 

Cheers

Al

 

<microsoft.web>

    <webServices enableBrowserAccess="true" />

  microsoft.web>

 

 

Only once per page you need to add this tag. So if you are using master pages, this is where you want to add this:

 

<atlas:ScriptManager id="ScriptManager" EnablePartialRendering="true" runat="Server">atlas:ScriptManager>

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

All this will provide you with Atlas in any web project with ASP.NET 2.0 and Visual Studio 2005. Start playing with

<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional">

They are very powerful.

 

Cheers

Al

 

 

Only once per page you need to add this tag. So if you are using master pages, this is where you want to add this:

 

<atlas:ScriptManager id="ScriptManager" EnablePartialRendering="true" runat="Server">atlas:ScriptManager>

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

Also you need to register the DLLS on the page:

@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit"

 

All this will provide you with Atlas in any web project with ASP.NET 2.0 and Visual Studio 2005. Start playing with

<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional">

They are very powerful.

 

Cheers

Al

Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (5)

Lately I just want to put skeletons of classes I use the most so I got a repository of code at my fingertips.

 

Creating a control for your toolbox in ASP.NET 2.0 is very easy using the new class CompositeControl from C# 2.0. Well VB and J# also have that class, but I just try very hard to forget those 2 languages exist.

 

CompositeControl is very powerful, you can create a control using existing controls. For example you can create a new control using the TreeView and a Label you create a control like the Microsoft search control. You can put a dropdown and a textbox to create a better dropdown.

 

This is the skeleton for using CompositeControl to create a checked treeview with a label as Microsoft msdn menus.

 

[DefaultProperty("Text")]

    [ToolboxData("<{0}:DropDown1 runat=\"server\"> </{0}:DropDown1>")]

    public class DropDown1 : CompositeControl

    {

        private TreeView m_TreeView;

        private Label m_Label;

        private ArrayList aItems = new ArrayList();

        private ArrayList aSelectedItems = new ArrayList();

       

        [Bindable(true)]

        [Category("Appearance")]

        [DefaultValue("Extending the DropDown control")]

        [Localizable(true)]

        public virtual String Title

        {

            get

            {

                if (ViewState["Title"] == null)

                    return ("No Title");

 

                return ((string)ViewState["Title"]);

            }

            set

            {

                ViewState["Title"] = value;

            }

        }

 

        public string Children

        {

            get

            {

                if (ViewState["Children"] == null)

                    return ("");

 

                return ((string)ViewState["Children"]);

            }

            set

            {

                ViewState["Children"] = value;

            }

        }

 

        [Bindable(true)]

        [Category("Appearance")]

        [DefaultValue("Extending the DropDown control")]

        [Localizable(true)]

        public void Items(ArrayList aList)

        {

            aItems = aList;

            for (int i = 0; i < aItems.Count; i++)

            {

                TreeNode oNode = new TreeNode(aItems[i].ToString());

                m_TreeView.Nodes.Add(oNode);

            }

        }

 

        public ArrayList GetSelectedItems()

        {

            return (aSelectedItems);

        }

 

        protected override void CreateChildControls()

        {

            m_TreeView = new TreeView();

            m_TreeView.ExpandImageUrl = "~/images/dropdown.gif";

            m_TreeView.CollapseImageUrl = "~/images/dropdown.gif";

            m_TreeView.ShowCheckBoxes = TreeNodeTypes.Leaf;

            //m_TreeView.NodeIndent = 0;

            m_TreeView.ForeColor = Color.Black;

            m_TreeView.TreeNodeCheckChanged += new TreeNodeEventHandler(m_TreeView_TreeNodeCheckChanged);

            m_TreeView.TreeNodeCollapsed += new TreeNodeEventHandler(m_TreeView_TreeNodeCollapsed);

           

            m_Label = new Label();

 

            TreeNode oNode = new TreeNode(Title);

            m_TreeView.Nodes.Add(oNode);

            if ( Children.Length > 0 )

            {

                ArrayList aChildren = GetChildren(Children);

                for (int t = 0; t < aChildren.Count; t++)

                {

                    TreeNode oNodeSub = new TreeNode(aChildren[t].ToString());

                    oNode.ChildNodes.Add(oNodeSub);

                }

            }

 

            this.Controls.Add(m_TreeView);

            this.Controls.Add(m_Label);

 

            //base.CreateChildControls();

        }

 

        private ArrayList GetChildren(string sChild)

        {

            ArrayList oArray = new ArrayList();

 

            while (sChild.IndexOf(",") != -1)

            {

                int len = sChild.IndexOf(",");

                string sTemp = sChild.Substring(0, len);

                oArray.Add(sTemp);

                sChild = sChild.Substring(len + 1);

            }

 

            oArray.Add(sChild);

 

            return (oArray);

        }

 

        protected override void OnPreRender(EventArgs e)

        {

            base.OnPreRender(e);

            /*if (Page != null)

                Page.RegisterRequiresPostBack(this);

             * */

        }

 

        [

        Category("Action"),

        Description("Raised when the user checks.")

        ]

        protected void m_TreeView_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)

        {

            BuildLabel(m_TreeView, m_Label);

        }

 

        [

        Category("Action"),

        Description("Raised when the user collapses the treeview.")

        ]

        protected void m_TreeView_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)

        {

            BuildLabel(m_TreeView, m_Label);

        }

 

        private void BuildLabel(TreeView oView, Label oLabel)

        {

            aSelectedItems.Clear();

            oLabel.Text = "";

 

            for (int i = 0; i < oView.Nodes.Count; i++)

            {

                for (int j = 0; j < oView.Nodes[i].ChildNodes.Count; j++)

                {

                    if (oView.Nodes[i].ChildNodes[j].Checked == true)

                    {

                        if (oLabel.Text.Length > 0)

                            oLabel.Text += ",";

 

                        oLabel.Text += oView.Nodes[i].ChildNodes[j].Text;

                        aSelectedItems.Add(oView.Nodes[i].ChildNodes[j].Text);

                    }

                }

            }

        }

 

        protected override void Render(HtmlTextWriter writer)

        {

            AddAttributesToRender(writer);

 

            writer.AddAttribute(

                HtmlTextWriterAttribute.Cellpadding,

                "1", false);

            writer.RenderBeginTag(HtmlTextWriterTag.Table);

 

            writer.RenderBeginTag(HtmlTextWriterTag.Tr);

            writer.RenderBeginTag(HtmlTextWriterTag.Td);

            m_TreeView.RenderControl(writer);

            writer.RenderEndTag();

            writer.RenderBeginTag(HtmlTextWriterTag.Td);

            m_Label.RenderControl(writer);

            writer.RenderEndTag();           

            writer.RenderEndTag();

                       

            writer.RenderEndTag();

        }

 

    }

Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (1)

Finally many unknowns on the problems with VS2005 have been “resolved”. Found this post on the msdn blogs from PeterL a Visual Web Developer Tester http://blogs.msdn.com/petel/archive/2006/07/03/655422.aspx

Lettings us know that cleaning the registry or screwing with the registry is not a good idea. Actually a few tools that claim cleaning the registry is not a good idea, this may prove that. How a tool knows what keys are actually safe to remove?

 

Please keep sending me emails about your problems with Visual Studio 2005. I have been trying to reproduce them as well as log the results. Hopefully one of these weekends I’ll add them all in a post with possible solutions.

 

Cheers

Al

Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (0)

I have been working in a Load balancer for a web server, with the news of IIS 7 I stop the project and I’ll start working in the new Load Balancer for IIS7.  http://forums.iis.net/thread/1297689.aspx

 

You can find the control if you want to play with it at

http://alpascual.com/control/loadbalancer.htm

This is a great load balancer without using any hardware, only issue, you are going to need to dns every computer with a different name:

www1.domain.com

www2.domain.com

www3.domain.com

 

Please any feedback will be very helpful to develop my next control for IIS7.

 

IIS7 comes with a great API to allow developers to get control of the web server, something that all of us have been waiting for a very long time. This is the link to develop modules for IIS 7: http://www.iis.net/default.aspx?tabid=2&subtabid=25&i=942

There is also an API for C++ : http://www.iis.net/default.aspx?tabid=2&subtabid=25&i=938

 

So no more interrogating the metadata of IIS6 or making requests to check if the server is down.

 

Cheers

Al

Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (4)

I have been working in a Load balancer for a web server, with the news of IIS 7 I stop the project and I’ll start working in the new Load Balancer for IIS7.  http://forums.iis.net/thread/1297689.aspx

 

You can find the control if you want to play with it at

http://alpascual.com/control/loadbalancer.htm

This is a great load balancer without using any hardware, only issue, you are going to need to dns every computer with a different name:

www1.domain.com

www2.domain.com

www3.domain.com

 

Please any feedback will be very helpful to develop my next control for IIS7.

 

IIS7 comes with a great API to allow developers to get control of the web server, something that all of us have been waiting for a very long time. This is the link to develop modules for IIS 7: http://www.iis.net/default.aspx?tabid=2&subtabid=25&i=942

There is also an API for C++ : http://www.iis.net/default.aspx?tabid=2&subtabid=25&i=938

 

So no more interrogating the metadata of IIS6 or making requests to check if the server is down.

 

Cheers

Al

Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (4)

Http Modules in ASP.NET 2.0 makes live so easy to separate the HTTP layer from the UI. You can add as many HTTP Modules as you require or add modules inside only one HTTP Module. Useful ones are:

 

Compressing the response back to the browser. When using IIS 5 this is a great module to add in all your solutions.

Easy URL paths. Used by forums.asp.net.

Installing a new Session Manager, copywriter notice, etc …

 

This is the skeleton of an HTTP. As you can see you need to inherited from IHttpModule so will create the functions Dispose() and void Init(HttpApplication context); for you.

 

 

Lets look at a compression HttpModule:

 

class AlHttpModule : IHttpModule

    {

 

        public AlHttpModule()

        {

 

        }

 

        #region IHttpModule Members

 

 

        public void Dispose()

        {

            // Clean any resources you may used

        }

 

        public void Init(HttpApplication context)

        {

            context.BeginRequest += new EventHandler(context_BeginRequest);

        }

 

        #endregion

 

        public void context_BeginRequest(object sender, EventArgs e)

        {

            HttpApplication app = (HttpApplication)sender;

 

            string encodings = app.Request.Headers.Get("Accept-Encoding");

 

            // No encodings stop the HTTP Module processing

            if (encodings == null)

                return;

 

            if (app.Request.Url.AbsolutePath.IndexOf(".aspx") == -1 &&

                app.Request.Url.AbsolutePath.IndexOf(".asmx") == -1 )

                return;

 

            Stream baseStream = app.Response.Filter;

 

            encodings = encodings.ToLower();

 

            if (encodings.Contains("gzip"))

            {

                app.Response.Filter = new GZipStream(baseStream, CompressionMode.Compress);

                app.Response.AppendHeader("Content-Encoding", "gzip");

            }

            else if (encodings.Contains("deflate"))

            {

                app.Response.Filter = new DeflateStream(baseStream, CompressionMode.Compress);

                app.Response.AppendHeader("Content-Encoding", "deflate");

            }

        }

    }

 

 

As you can see .Request.Url.AbsolutePath is where everything happens. You can create a simple easy URL path like used by http://forums.asp.net by just looking at Request.Url.AbsolutePath and using Server.Transfer() to the right page. So people can browser to http://domain.com/1244 and you can convert that to Server.Transfer(“http://domain.com/Page.aspx?id=1244”);

 

Cheers

Al