Pages

Thursday, February 19, 2009

Ignore query in jQuery treeview persist location

The jQuery treeview plugin can be found here, it is a brilliant plugin which makes amazing treeviews.

But when i use:

persist: "location"

 I run into a little "problem", because i would like to have the treeview item selected when i use query's in the URL, and as default it just doesn't select any when using query.

What I need to do is to detect if there is a query in the url and then ignore it, I've done it the following way:

case "location":

var current = this.find("a").filter(function()
{
    return this.href.substring(0, (this.href.indexOf("?") == -1) ? this.href.length: this.href.indexOf("?")).toLowerCase() == location.href.substring(0, (location.href.indexOf("?") == -1) ? location.href.length: location.href.indexOf("?")).toLowerCase();
});

It is a pretty simple fix and works like a charm!


 

EDIT:

This version is also able to handle bookmarks and query in url.

case "location":

var current = this.find("a").filter(function()
{
    var linkLength = (this.href.indexOf("?") != -1) ? this.href.indexOf("?") : (this.href.indexOf("#") != -1) ? this.href.indexOf("#") : this.href.length;
    var link = this.href.substring(0, linkLength);

    var urlLength = (location.href.indexOf("?") != -1) ? location.href.indexOf("?") : (location.href.indexOf("#") != -1) ? location.href.indexOf("#") : location.href.length;
    var url = location.href.substring(0, urlLength);

    return link.toLowerCase() == url.toLowerCase();
});

Wednesday, February 18, 2009

Windows remote desktop security

I've been wondering about how secure Windows Remote Desktop actually is, and it seems like you can be pretty protected with some common sense and few changes.
Here are a few tips that I have found while searching:
  • As default all administrators has remote desktop access, so it is a good idea to change the Administrator users name to a different name.

    1. It is found in: Control Panel -> Administrative Tools -> Local Security Policy -> Local Policies -> Security Options
    2. Find: "Accounts: Rename administrator account" in the list, and right click and Properties.
    3. You are able to rename the administrator name here, and then restart the computer.
    4. While your in the Local Policies you can change the values in the Account Policies to be as you want it, like changing the: Account lockout threshold to a few attempts.
  • Another thing is to change the default port number of remote desktop which is 3389, it can be changed the following way.
    1. Go to: Start -> Run -> write "regedit" -> press OK.
    2. Go to the following folder: HKEY_LOCAL_MACHINE -> System -> CurrentControlSet -> Control -> TerminalServer -> WinStations -> RDP-Tcp
    3. Find: "PortNumber" in the list, and right click and "Modify..."
    4. Write your desired port number and remember to add ":PortNumber" at the end of the URL when connecting to your Remote Desktop, and be sure to check if the firewall port is open.

Saturday, February 14, 2009

Convert your Windows Server 2008 to a Workstation

I use windows server 2008 as a workstation myself, and there are significant changes which can be made to make it much better as a workstation.
A great site that i used to reconfigure mine is: win2008workstation.com, there is guides to everything, from disabling the shutdown tracker to performance increases and much more!
..i can warmly recommend it, because it gives a better workstation experience on a awesome OS.

Friday, February 13, 2009

Saving changes is not permitted in Microsoft SQL Server Management Studio 2008

If you try to change columns in a table that you've created you will get the following message:

"Saving changes ins not permitted. The changes you have made require the following table to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.". I think this option isen't very useful as enabled by default.

The message explains itsel, you have to disable the "Prevent saving changesthat require the table to be re-created", but where is this option.
Tools -> Options -> Table and Database Designers -> Uncheck "Prevent saving changes that require the table to be re-created"

Sunday, February 8, 2009

Aviary editors is worth trying

My friend said I should check this link, and so i did: aviary.com

I looked at it and found a lot of pretty cool "editors" or as they say it: "creation accessible to artists of all genres, from graphic design to audio editing.".

I don't like flash very much, but i must say it is the best browser based photo editor I've ever seen, and properly also the only one ;)

I haven't checked out the others that much, but I'm sure they are just as nice. So if you need a photo editor on the fly i would recommend the one Aviary Phoenix Image Editor.

Friday, February 6, 2009

Request file from javascript created file uploads

If you want the files from your file uploads you normally use:

Request.Files

But when the file uploads is created using javascript like so:

var element = document.getElementById("ctl00_ContentPlaceHolder1_DdlFileCount");

var Value = element[element.selectedIndex].value;

var container = document.getElementById("TextboxContainer");

container.innerHTML = "";

for (var i = 0; i < Value; i++) {

    container.innerHTML += "<input class='textbox' type='file' name='FileUpl" + i + "' id='FileUpl" + i + "' /><br />";

}

The Request.Files won't detect the files uploaded by the client using the dynamic file upload.


The reason why, is because asp.net at compile time creates an Enctype in the form, this wont get created when client-side scripting is doing the creating of control.

My friend found a pretty simple solution, where you just need to add the following line to your page load event:

Form.Enctype = "multipart/form-data";

After that you are able to Request.Files like you normally would do from asp.net controls.

Thursday, January 29, 2009

Project - Breakfast Bringer

Problem

We have a computer showing an excel document at work, which shows who has to get breakfast on the particular day. I thought it could be made a lot smarter, and that's why i started this fun mini project, but also to get a better understanding of Windows application, because they are relatively new for me.

Solution

Create a small windows application which will keep track on who has to get breakfast each day.


The language is Danish, so you will have to translate if you don't get the main functionality.

Saturday, January 24, 2009

I got my first motorcycle: Yamaha XV250 Virago

I took by motorcycle drivers license, in the spring last year.
It was quite a struggle to go through the last summer without being able to cruise in the warm breeze, and that's why i coulden't let that happen this summer! ;)

So I'm now the proud owner of a Yamaha XV250 Virago, which has driven some miles, so I've been fixing the outer parts and got the part that needed a change for the past week.
And yesterday it was time to fire it up, and it sounded awesome! and drives like a dream, and now I'm only waiting on the weather!

Thursday, October 16, 2008

A quick introduction to jQuery

I've been looking at jQuery for some hours now, and i must say that im amazed! It's very light-weight and incredibly powerful with it's big library and ui.
Here is a list with some of the links i found use full in my quest to learn jQuery:
I haven't played arround with it a lot, but I will do it as soon as posible, so there will be a bigger introduction with examples etc. later on.

Monday, October 13, 2008

Monitor color test

I read this funny blog post on mha today, it's about a color test, which can give you an indication on how good your monitor is.
It's pretty simple, you have to sort the color variations to match each other. I thought this would be a great way to test my new Philips 240BW8EB, and i must say it passed with flying colors:

It turned out perfectly, but i must say that your eyes has to be a little good to, which mine i'sent, so i relied on my monitor :P
you can try out the test here: Color Test, to see how good your monitor/eyes is.

Wednesday, October 8, 2008

I just bought the Philips 240BW8EB LCD monitor

I've finally gone *dual screen* at home, after some years with my little 19" i thought it was time to get a little more room on my digital desktop, so that why i bought this amazing Philips 240BW8EB.

I'm pretty impressed with the image quality, taking the price in consideration. It's a great buy and i can recommend it to all who want to have a big, cheap and good full HD LCD monitor. 

If you want to see images of how it's displaying image etc, then just leave a comment, and I'll post some pics. I've taken af color test, you can check out the resoults here: Monitor color test

Thursday, September 25, 2008

Create data paging using linq

As everyone probably know and have tried, is the ASP.NET integrated paging system in the data sources, but it's not always it fits your solution. That's why i want to show you how i make simple data paging using query.

Getting data access

To start off we need to get access to the database, to do this i use LINQ by creating a .dbml file, within this example contains products from the sample database Northwind.

I'm creating a simple method to get the data out:

public static List<Product> GetProducts()
{
   PagingDataContext db = new PagingDataContext();
   
   return (from p in db.Products
           select p).ToList();
}

I will use the skip and take in linq to make the paging:

.Skip(skip).Take(take); 

Create paging class

Now we need the class that can convert pageNumber and pageSize to skip and take, in my case I've made a Paging object that can contain the take, skip and totalPages integers:

public static Paging GetTakeAndSkip(int pageNumber, int pageSize)
{
   int take = pageSize;
   int skip = (pageNumber - 1) * pageSize;

   //(totalProducts / pageSize)
   int totalPages = Int32.Parse(Math.Ceiling(decimal.Parse(ProductService.GetProducts().Count().ToString()) / decimal.Parse(pageSize.ToString())).ToString());

return new Paging(take, skip, totalPages);
}

Putting it all together

This is just databound to a gridView to give you an example, and the page size is defined in the query. You can make a drobdownlist or so to handle how many to be displayed, but that's not made in this example:

int pageNumber;
int pageSize;
Paging pagingItem;

protected void Page_Load(object sender, EventArgs e)
{
   //Request the queries, to make it more secure
   //put IsNullOrEmpty and tryParse arround.
   pageNumber = Int32.Parse(Request.QueryString["page"]);
   pageSize = Int32.Parse(Request.QueryString["size"]);

   //Requesting the Method in the paging class
   pagingItem = Paging.GetTakeAndSkip(pageNumber, pageSize);

   //This keeps track of the number and size
   LitPagePlace.Text = string.Format("{0}/{1}", pageNumber, pagingItem.TotalPages);

   //Using the skip and take on our method to get products
   GridProducts.DataSource = ProductService.GetProducts().Skip(pagingItem.Skip).Take(pagingItem.Take);
   GridProducts.DataBind();
}

protected void LinkNext_Click(object sender, EventArgs e)
{
   //This will make it stop paging,
   //when the last page is reached
   if (pagingItem.TotalPages > pageNumber)
   {
      //replacing and redirecting to the next page
   Response.Redirect(Request.RawUrl.Replace(string.Format("page={0}", pageNumber),

   string.Format("page={0}", pageNumber + 1)));
   }
}

protected void LinkPrev_Click(object sender, EventArgs e)
{
   //This will make it stop paging,
   //when the first page is reached
   if (1 < pageNumber)
   {
      //replacing and redirecting to the previous page
      Response.Redirect(Request.RawUrl.Replace(string.Format("page={0}", pageNumber),

      string.Format("page={0}", pageNumber - 1)));
   }
}

Thursday, August 14, 2008

Firefox must have Addons

As everyone knows, Firefox is the best browser! ..and they have tons of add-ons to customize the browser after your needs.

But the add-ons can easily become a jungle, there is a lot of good add-ons but also a lot of bad once, so I've decided to make a list of my favorite Firefox Add-ons(for 3.0):

Firebug: Just a great extension developer tool which let's you edit and debug things like JavaScript.

Web Developer: Another developer tool where you can do everything from test screen resolution to make div boxes visible, a very good Add-on to research and get experience.

Flagfox: Let's you see where the web server is placed in the world and you can also see the IP.

IE Tab: As every web developer knows, there is a big gab in browser rendering especially in the two most popular browsers, Internet Explore and Firefox. You need to test your sites in both browsers fast and easy, and this Add-on does exactly that. Very nice tool and i use it alot.

YSlow: Is your website slow? test it and see what's wrong with this tool.

All the addons can be found here: addons.mozilla.org just search on the add-on and you will find the newest version.

Wednesday, August 13, 2008

How to install AJAX Toolkit on framework 3.5

I got this problem when I had installed Visual Studio 2008 on my new computer, and I had no clue on how to solve it. But then my friend came with a suggestion that have helped him with the same problem, and it worked! So I thought, there must be someone else out there that’s having the same problem. This is how I solved it:
The problem seem to be because VS2008 install a compact edition of Framework 3.5, so you need to get the full package of Framework 3.5 which can be found here - you scroll down and click on the: .NET Framework 3.5 full package.
Now you are ready to install AJAX Control Toolkit to your computer and that is available here - And remember to take the AjaxControlToolkit-Framework3.5, either with or without source.

The last think to do is to save the Bin some place on your computer and "Choose items.." is VS2008 Toolbox.
I hope this will help you as much as it helped me :D

Tuesday, July 22, 2008

New development machine

I have finally got my new computer build, and it is now up and running pretty good.
Here is the hardware:
  • Motherboard: ASUS P5Q PRO
  • CPU: Intel Core 2 Quad Q9300 @ 2,5GHz
  • Graphic card: MSI NVIDIA GeForce 8600GT
  • Harddisk: 2x Seagate Barracuda 320GB 24/7
  • RAM: 2x Samsung 2GB  UPDATE: 2x Geil Black Dragon 2GB (8GB FTW)
  • Tower: Antec Performance One P182
  • PSU: Corsair TX750W
And now for the obligatory software:
Windows Server 2008, Visual Studio 2008, sql server 2008  **Heroes happen {here}**