August 29th, 2007 — .NET, Code, Work
When you write a Server Control and write it well, it pays off immensely. Today, I needed to rework our Custom Defaults screen (a screen that allows each user to define defaults for our quoting screens to use each time they write a new quote). All of the fields on the Custom Defaults screen exist in the quote (duh, why would we provide something that didn’t?
).
Since everything in the quote is a server control, it was just drag and drop the controls onto the Custom Default page and it would act 100% like it does in the quote.
It could not have gone any faster, I probably only spent close to 5 minutes setting up the design and flow and 30 minutes getting the code behind functionality to work.
Thus, harness the power of Server Controls as they can be reused across numerous applications with little trouble and little programming.
August 20th, 2007 — .NET, Code, Work
Today, Aaron and I were wondering if ViewState actually works properly in .NET. For example, in .NET you have the option to disable ViewState in the web.config file, the page directive, or on each control individually. However, using any of the three methods or any combination continuously results in “__VIEWSTATE” appearing as a hidden field in the form!
The problem gets worse when you try to submit the form to another page by overriding the form’s action. This throws an “ViewState is corrupt or invalid for this page.” error. We finally got around it by hacking a JavaScript event to empty the “__VIEWSTATE” hidden field so it had nothing in it before the form actually submitted the page. But is that the only way to get rid of ViewState?
Code to cause ViewState corruption:
<script type="text/javascript">
window.onload = function()
{
document.getElementById('Form1').onsubmit = function()
{
document.getElementById('Form1').action = '/another_project/another_page.aspx';
}
}
</script>
How, we got around it:
<script type="text/javascript">
window.onload = function()
{
document.getElementById('Form1').onsubmit = function()
{
var inputFields = document.getElementsByTagName('input');
for (var i = 0; i < inputFields.length; i++)
{
if (inputFields[i].name.toUpperCase() == "__VIEWSTATE")
{
inputFields[i].value = ""; // Empty the ViewState hidden field to stop it from carrying on to the next page
break;
}
}
document.getElementById('Form1').action = '/another_project/another_page.aspx';
}
}
</script>
Anyone else have a problem like this?
August 17th, 2007 — Kubuntu, Linux, Ubuntu
This is a technique I constantly forget when I absolutely need it, and so I am going to post it for future reference as I hate trying to figure out over and over again.
So here is the big secret. First get a Linux distrobution that allows you to use a Live CD. Boot up the computer you wish to backup with the Live CD. While that is happening, get on your primary PC (that is hopefully running Linux) and type the following command and run it:
netcat -l -p 1234 | dd of=backup.img bs=16065b
Once the Live CD is booted, start up the terminal/konsole and run the following (must be ran after the prior command):
sudo dd if=<hard drive partition to backup> bs=16065b | netcat <linux PC's IP Address> 1234
That’s it! It will now backup the hard drive partition you selected on the PC running the Live CD. So easy!