Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Sunday, April 29, 2007

My article has been written for MSDN now and so I'm back to blogging. The article wasn't done quite as well as I would have hoped because I've got about three or four other things going on at the same time right now and so focus has been thin; but it was an article and we'll see if it makes its way through the submission process.

Apart from that I have decided that I'm going to blog on the ASP.NET AJAX control toolkit for the next month or two, exploring each of the control's from the inside out and teaching people how to use them. Hopefully I can even contribute some of the things I write to the community project itself. Regardless, my hope is that we can all explore the internals of the AJAX controls a bit and begin to leverage them more productively.

I'll continue posting answers to people's questions too.

I'm going to go alphabetically through the control toolit, so starting tomorrow we'll begin an exploration of the Accordion control and I'll try to spend, at least, a couple days (maybe even a week) on each control.

Cheers.


kick it on DotNetKicks.com
Sunday, April 29, 2007 2:38:34 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback

 Wednesday, April 18, 2007

I have been busy :)

Currently I'm writing an article for MSDN detailing the internals of the ScriptManager; and so between that and work I have had next to no spare time to really do anything else. When the article if done then I'll have plenty of time for exploring ASP.net, AJAX, .Net and the like...but for now, I gotta get this article done!

Thanks....

(about another couple days, probably)


kick it on DotNetKicks.com
Wednesday, April 18, 2007 9:01:16 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback

 Thursday, April 12, 2007

I quickly through this sample together because someone in the newsgroups wanted a way to create a filesystem view through the ASP.Net TreeView control. Note: I'm not touching this with icons or any other niceness, that's an exercise left to the reader:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<script runat="server" language="C#">
    protected void Page_Load(object sender, EventArgs e)
    {
        System.IO.DirectoryInfo di =
            new System.IO.DirectoryInfo(@"c:\mydirectory\mydirectoryschild\");
        TreeNode root = new TreeNode(di.Name);
        this.TreeView1.Nodes.Add(root);
        HydrateTree(di, root);
    }

    private void HydrateTree(System.IO.DirectoryInfo dir, TreeNode parent)
    {
        foreach (System.IO.FileInfo file in dir.GetFiles())
        {
            parent.ChildNodes.Add(new TreeNode(file.Name));
        }
        foreach (System.IO.DirectoryInfo di in dir.GetDirectories())
        {
            TreeNode child = new TreeNode(di.Name);
            parent.ChildNodes.Add(child);
            HydrateTree(di, child);
        }
        return;
    }
</script>
<asp:TreeView ID="TreeView1" runat="server">
</asp:TreeView>

This is what it looks like on my machine:



Recommended reading:


kick it on DotNetKicks.com
Thursday, April 12, 2007 7:37:08 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
ASP.Net | Programming
 Tuesday, April 10, 2007

Kind of an interesting mental exercise. Say you wanted to enumerate all the classes in any particular namespace. Unfortunately there doesn't appear to be a way to say, "Get all classes in a namespace" using reflection, so you kind of have to roll your own implementation. But, this is how I did it....

namespace TestingGroundsCSharpConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Assembly a = Assembly.GetExecutingAssembly();
            List<String> namespaces = new List<string>();
            foreach (Type t in a.GetTypes())
            {
                if (t.Namespace == "TestingGroundsCSharpConsole")
                    namespaces.Add(t.Name);
            }

            foreach (String s in namespaces)
                Console.WriteLine(s);

            Console.ReadLine();

            return;
        }
    }

    class Class1
    {
        private Int32 _myInt;
    }

    class Class2
    {
        private Int32 _myotherInt;
    }
}

....the output is

Program
Class1
Class2



kick it on DotNetKicks.com
Tuesday, April 10, 2007 10:07:02 PM (Central Standard Time, UTC-06:00)  #    Comments [1] - Trackback
Programming | .Net Runtime

You more than likely get this exception when you attempt to use the "My.Settings" object through ASP.Net. Settings scoped for the user are valid for WinForms or other such desktop applications which typically run under a particular user account, but ASP.Net accounts run, usually, under a special server or ASP.Net account - therefore this object will throw an exception when used in this context.

The best way around this is to use ConfigurationManager.AppSettings for settings, or Profiles for per-user configuration in ASP.Net 2.0.


kick it on DotNetKicks.com
Tuesday, April 10, 2007 6:57:55 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
ASP.Net | Programming

I saw a question in the newsgroups about this and I thought I would post about it right quick; "how do you manually set focus with javascript". Using .Net it's easy, you simply call .Focus() on a server control:

this.LinkButton1.Focus();

But if you have to do it from script within a page itself, you do it this way:

<html id="total" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body id="Body" onload="document.form1.Text2.focus();">
    <form id="form1" runat="server" style="width:1000px;height:1000px;" >
        <div  >
           <input id="Text1" type="text" /><input id="Text2" type="text"/>
        </div>
    </form>
</body>
</html>

Notice the onload event within the body. This will effectively focus the cursor within Text2. Obviously you don't have to limit it to the body onload event, you can do it from any event or any script; I just did it there from my example.

Easy as cake.


kick it on DotNetKicks.com
Tuesday, April 10, 2007 6:46:23 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
ASP.Net | JavaScript | Programming
 Sunday, April 08, 2007

Thanks to Sebastian and his source here for my direction on this topic. Cheers man; I owe you Guinness.



There seems to be a severe lack of writing on the internet about how to do just this very thing - slowly blending one image to another using DirectX. I'm not an expert at DirectX, I spend most of my time these days doing web-based development, but I am also a software consultant and so get picked up for different types of jobs from time to time, and obviously it makes no sense to turn a job down....



....well, I wanted to implement a system where one texture slowly blended into another texture; kind of like a slow fade effect. As it turns out it's pretty trivial, but again not something I was very good at....



To do this correctly, you really want to do it independent of the image format, so that whether you're using something that has an alpha layer in it or not is irrelevant (like, a JPG vs. a PNG). To do this, you fill in or interpolate the alpha value of an image acrossed it using the vertices in the vertex buffer. So - you need to make sure that your vertices have an alpha color component. Likewise, to change the degree by which something blends, you change the alpha components of each vertex in the buffer. This actually gives you great control over the blending because you can choose even more advanced scenarios than simply blending from one image to another - you can also choose where to start the blending (from a particular corner to another, etc.).

So, on to the code....in the drawing loop for the application (if you're implementing your DirectX application correctly, this should be the Paint method):

        private void Form1_Paint(object sender, PaintEventArgs e)
        {

            _device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
            _device.BeginScene();

            if (_zoomIn)
            {
                _alphaValue++;

                if (_alphaValue == 255)
                    _zoomIn = false;
            }
            else
            {
                _alphaValue--;
                if (_alphaValue == 0)
                    _zoomIn = true;
            }
            _verts[0] = new CustomVertex.PositionColoredTextured(-1.0F, 1.0F, 0.0F, Color.FromArgb(_alphaValue, Color.White).ToArgb(), 0.0F, 0.0F);
            _verts[1] = new CustomVertex.PositionColoredTextured(1.0F, 1.0F, 0.0F, Color.FromArgb(_alphaValue, Color.White).ToArgb(), 1.0F, 0.0F);
            _verts[2] = new CustomVertex.PositionColoredTextured(-1.0F, -1.0F, 0.0F, Color.FromArgb(_alphaValue, Color.White).ToArgb(), 0.0F, 1.0F);
            _verts[3] = new CustomVertex.PositionColoredTextured(1.0F, -1.0F, 0.0F, Color.FromArgb(_alphaValue, Color.White).ToArgb(), 1.0F, 1.0F);
            _verts[4] = new CustomVertex.PositionColoredTextured(-1.0F, -1.0F, 0.0F, Color.FromArgb(_alphaValue, Color.White).ToArgb(), 0.0F, 0.0F);
            _verts[5] = new CustomVertex.PositionColoredTextured(1.0F, -1.0F, 0.0F, Color.FromArgb(_alphaValue, Color.White).ToArgb(), 1.0F, 0.0F);

            _buffer.SetData(_verts, 0, LockFlags.None);

            _device.VertexFormat = CustomVertex.PositionColoredTextured.Format;
            _device.SetStreamSource(0, _buffer, 0);

            _device.SetTexture(0, _texture);
            _device.SetTexture(1, _texture2);

            _device.TextureState[1].TextureCoordinateIndex = 0;

            _device.SamplerState[1].AddressU = TextureAddress.Wrap;
            _device.SamplerState[1].AddressV = TextureAddress.Wrap;


            _device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
            _device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);
            _device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
            _device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
            _device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.BlendDiffuseAlpha);

            _device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

            _device.EndScene();
            _device.Present();

            Invalidate();
            return;
        }

The effect is two textures that slowly blend back and forth to each other.


Recommended Reading

kick it on DotNetKicks.com
Sunday, April 08, 2007 2:07:54 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
DirectX and XNA | Programming
 Thursday, April 05, 2007

ASP.Net doesn't like multiple forms on a webform; indeed, it is the paradigm now that one webform has one "form" on it (hence the name - webform). However, as people begin buliding tricky input forms on their pages it becomes necessary to specify "default" buttons throughout the page. As an example, say you're filling out one of two forms on a page and you want to hit the Enter key to submit your form data. If there are multiple forms on the page, then you will run into a problem as the browser attempts (and possibly fails) to ascertain which button should recieve the keydown event.

In ASP.Net the Panel control supports a default button so that you can "subsection" out your form with various different buttons being the default. If focus happens to be on a control within a panel that has one of these secondary submit buttons specified, then THAT button will get respond to your Enter keystroke.

Here's an example:

First, create a webform with two panels on it like this:



When you run the above form, regardless of whether your cursor is in the textbox of the first form or the second form, hitting ENTER will always act as if you clicked the button in the first.

To submit the button in the second via the ENTER key if your cursor is active in that textbox (or any control in that panel), do the following to the panels:

            First form:
            <asp:Panel ID="Panel1" DefaultButton="Button1" runat="server" Height="127px" Width="151px">
                &nbsp;
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" /></asp:Panel>
            <br />
            Second form<br />
            <asp:Panel ID="Panel2" DefaultButton="Button2" runat="server" Height="127px" Width="151px">
                &nbsp;
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" /></asp:Panel>
            </div>

Notice how I specify the "DefaultButton" property in the panel. Now if your cursor is active in any control within Panel2, Button2 will be the default submit button for your ENTER keystroke.

Addendum:

Please see here for the documentation to this attribute. It is available in the .Net frameworks 2.0 and 3.0 only.

Recommended reading:


kick it on DotNetKicks.com
Thursday, April 05, 2007 9:04:17 PM (Central Standard Time, UTC-06:00)  #    Comments [3] - Trackback
ASP.Net | Programming

Computers Blogs - Blog Top Sites

Archive
<April 2007>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)