by aherrick
23. July 2008 03:55
It can be a good idea to encrypt your connection string before deployment of an web application in ASP.NET. Plus, it's easy! Let me show you how.
In command prompt (start -> run -> cmd) navigate to your Asp.Net directory usually found at %WINDOWS%\Microsoft.Net\Framework\version
If you have already setup your application in IIS use the following synatx to encrypt:
aspnet_regiis -pe "connectionStrings" -app "/YourApplicationHere"
Similarly to decrypt:
aspnet_regiis -pd "connectionStrings" -app "/YourApplicationHere"
One thing to note, make sure you are encrypting the connection string on the production box. It will not work to encrypt your connection string on another box and move your web.config into production.
Let me know if this worked for you!
by aherrick
21. July 2008 00:54
I have been working with SubSonic for almost a year now and I love it. If you don't know, SubSonic is a data access layer that will automatically generate code to access your data along with a bunch of other really cool tools. Created by Rob Conery, check him out if you have not, version SubSonic 2.1 was just released. I'm going to try and blog about different things I pick up about SubSonic that I hope proves to be useful.
Creating a partial class to extend a a generated SubSonic class is easy! Let's take a look...
When creating SubSonic based projects, we like to create a class library to abstract SubSonic from the web project. You can name this project whatever you like.
In this example I am going to use the Products table from Microsoft's Northwind database. In my SubSonic project class I create a new folder to hold my partial class. I call the folder "DAL"
Create a new class in your DAL folder with the same name as the SubSonic class. For example, SubSonic generates "Product.cs". If you wanted to extend this class, the only trick is to put the keyword "partial" in your new class. See below.
I am going to write a simple method to extend the generated SubSonic Product class. This method "GetProductsToOrder" will return a collection of products where UnitsInStock is less than 20. Of course this is just an arbitrary business rule used as an example. See the code below.
Now to use this method, since I made it static, I do not have to create a new instance of Product. I will set it equal to a ProductCollection and pass it an integer.
Now I have a collection of Products with less than twenty units in stock! Good luck writing your SubSonic partial classes and let me know how it goes!
by aherrick
9. July 2008 05:12
Today I was working on some code and I needed to validate a textbox input when the user attempted to leave the field. The javascript event onblur fit the bill nicely.
In the code behind I wired up my textbox like so:
this.txtAmount.attributes.add("onblur", "validate()");
This will hook the onblur event onto the textbox programatically. I find it appropriate to add events progrmatically since Visual Studio complains about adding events to the markup. While this will still compile and run just fine, there is much more flexiblity in adding events in the code behind.
Now for the javascript code. First I am setting a reference to my textbox and a hidden field on the form. The first check is a regular express to make sure my input is valid. I am looking for positive amount.
For example: 2 valid, 200 valid, 200.20 valid, 200.233 invalid, -200 invalid.
If input does not pass the regex, I throw an alert asking for valid input. If it passes regex, my second check is just some business logic.
That is all it takes to write a custom javascript validation for your code. Thank you!
by aherrick
8. July 2008 07:50
Today I was working on some code and I needed to programatically create a link with the ability to have a javascript pop up. The code is as follows:
string javascriptLink = "<a href=\"javascript: void(0)\" onclick =\"window.open('YourPageHere.aspx', '', 'scrollbars=0');return false;\">javascript link</a>";
To take this code a little further as in my case I needed to pass a query string to the page I wanted to load.
Edit your string like so:
string javascriptLink = "<a href=\"javascript: void(0)\" onclick =\"window.open('YourPageHere.aspx?Id=" + yourId + "', '', 'scrollbars=0');return false;\">javascript link</a>";
where yourId is the variable you want to pass.
Let me know if it worked for you. It's just that easy!
9eca0a68-d54a-4f08-9d4a-8ce3f47185ea|0|.0
Tags: javascript, c#
by aherrick
5. July 2008 06:41
A while back I had the need to use AJAX in one of my web projects. After some searching, I gathered the files and code necessary to fully integrate AJAX functionality into my code.
If you have not already, download and install the AJAX Control Toolkit and ASP.NET AJAX Extensions. The AJAX Control Toolkit will give you access to a bunch of really cool AJAX controls and extensions to aide in development. Check out the Control Toolkit demo page here.
Once both are downloaded and installed, add the following references to your project.
Finally, add the following code to the appropriate sections of your web.config file.
ajaxbits.txt (3.20 kb)
Let me know how it turns out!
by aherrick
4. July 2008 17:22
This is my first blog entry. My goal is to keep this updated every once and a while with useful and quality information. Thank you for checking me out!
2aa81bec-10a8-42d7-ae1e-2ed9d0085576|0|.0
Tags: welcome, blog