June 25th, 2008 Luke
For a recent project, I had to deal with a fair number of controls on a page that all needed to be disabled at once. This is the function that I wrote to do so:
void DisableControls(List types, ControlCollection controls) {
foreach(Control control in controls) {
if(types.Contains(control.GetType())) {
((WebControl)control).Enabled = false;
}
}
}
Posted in ASP.Net, Code, csharp, snippet | No Comments »
December 23rd, 2007 Luke
I really like SubSonic. I think out of everything that I’ve experienced with ASP.Net, SubSonic has to be the coolest thing I’ve encountered thus far(I’m not optimistic about finding anything cooler - SubSonic is pretty sweet).
However, each time that you create a new project that uses SubSonic, you have to do a few setuppy things - like creating an App_Code directory, and editing your web.config - that are virtually the same across pretty much every SubSonic project that you start.
So, to that end, I’ve created a few Visual Studio 2005 templates that should speed the process up.
They’re all ready to go, and all you need to do is fill in the $connectionstring$ in your web.config file - and then you’re good to go! They use SubSonic’s Build Provider to do all of the generating.
I made three template installers - one to install the VB template, one for the C# template, and one that installs both - just in case you want both of them.
Here are the downloads:
Enjoy!
Posted in ASP.Net, subsonic, templates | No Comments »
December 12th, 2007 Luke
Have you ever encountered a moment where you needed to store a DataReader into a DataTable?
I seem to all the time. And after reading through many, many articles where they just loop through the rows in the DataReader and add them to the destination DataTable, I thought to myself “there has to be a better way to do this”.
And there is. It’s surprisingly simple. Take a look:
DataTable myTable = new DataTable();
myTable.TableName = "MyTable";
myTable.load(myDataReader);
And that’s all there is to it. Upon inspection, you will see that myTable now has the contents of myDataReader inside of it.
Posted in ASP.Net, snippet | No Comments »
December 3rd, 2007 Luke
Have you ever stored an image in your database, only to find that it’s not quite the type of image you’re looking for?
Maybe you’d prefer a PNG or a TIFF, when all you’ve been given is a cruddy old JPEG.
Have no fear! C#’s Image is here!
All you need to do to convert an image from one type to another type is read it into an Image object, and then save it using the mime-type you want.
Image testImg = Image.FromFile("test.jpg");
testImg.Save("test.png", ImageFormat.Png);
And you’re done! Enjoy your shiny new .png file.
Posted in ASP.Net, image | No Comments »
November 29th, 2007 Luke
I recently build a quick textbox-based login page, which worked fine - until we tested it under IE and the form wasn’t submitting properly. If a user entered text into the textbox and pushed enter(under IE), instead of submitting the form it would just refresh the page(although it would post a postback). It took a friend and I a little while to figure out, but we eventually managed (through some googling) to resolve the issue. If you add this:
<input type="text" style="display:none" />
To your form, IE will properly submit the form.
Who would have thought?
Posted in ASP.Net, bug, ie, snippet | No Comments »