eWorld.UI - Matt Hawley
ME PRGM 4 U
-
Centrall IL Dot Net User Group - Upcomming Events
I've been starting to put together a nice lineup for future events for the Central IL Dot Net User Group based out of Bloomington, IL. Below is a brief summary of whats to come:
-
Snow?
EEEK! So I wake up this morning, go to my office, sit down in my chair... then I glance to my left - ITS WHITE OUT! AHHH! Why does it have to snow in the middle March? Well, I guess thats okay, because its supposed to be in the 60's by the end of the week.
-
Thinking Toys
A coworker of mine was just complaining how the cleaning crew had thrown away his bent-up paperclip that he played with while thinking this last weekend. This made me start to wonder what I play with when thinking about a problem while programming. It turns out that I actually have 2 different items.
-
"The http redirect request failed."
Ever got this message attempting to open a solution in VS.NET 2003? Well, the full error message is "The web server reported the following error when attempting to open or create the project at the following URL: The http redirect request failed." A co-worker ran across this multiple times on Friday, and got entirely fed up with the problem that he'd have to refresh the entire project from VSS or delete the /bin directory each time. I guess the root cause of this is something with the page named: "get_aspx_ver.aspx". After a call to MS, he came back with a solution:
protected void Application_BeginRequest(object sender, EventArgs e)
{
string ver = Request.ServerVariables["URL"].ToString();
if(ver.IndexOf("get_aspx_ver.aspx") >= 0)
Response.End
}
After the previous code was added to the global.asax file, our solutions started opening without any problem. -
Encode HTML - Have validateRequest = True
A co-worker and I had a situation today in which we wanted a particular TextBox control to allow HTML. The only problem, is that validateRequest must be done across the entire website, or for the particular page. Because of these restrictions, and the fact that the UserControl being built is placed in a dynamic page for a portal, we had to research ways to allow HTML posted entries but still keep validateRequest=True.
After doing a little bit of research, I came across the idea of replacing the character representation of common HTML elements via Javascript then decoding that information with Server.HtmlDecode.
The code is as follows:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Test.WebForm1"
Then in my code-behind I have this in my Page_Load function to add the onclick attribute:
validateRequest="true"%>
<html>
<body>
<form runat="server">
<script language="javascript">
function encodeMyHtml(toEncode) {
return toEncode.replace(/&/gi, '&').replace(/\"/gi, '"').replace(/</gi, '<').replace(/>/gi, '>');
}
</script>
<asp:TextBox Runat="server" ID="tbEncodedText" TextMode="MultiLine" Columns="100" Rows="10" >
<asp:Button Runat="server" ID="btnSubmit" Text="Submit My HTML" OnClick="btnSubmit_Click"/>
<hr>
<asp:Literal Runat="server" ID="outputHTML" />
</form>
</body>
</html>private void Page_Load(object sender, System.EventArgs e)
Then my button event, I have:
{
if(!Page.IsPostBack)
{
btnSubmit.Attributes.Add("onclick", "this.form." + tbEncodedText.ClientID + ".value = encodeMyHtml(this.form." + tbEncodedText.ClientID + ".value);");
}
}private void btnSubmit_Click(object sender, EventArgs e)
{
outputHTML.Text = Server.HtmlDecode(tbEncodedText.Text);
tbEncodedText.Text = Server.HtmlDecode(tbEncodedText.Text);
}
Overall, this provides a nice solution to not having your entire web application or page allow HTML elements. -
Reading Eventlog Entries
I was asked by my boss the other week, in my spare time at work, to create a script or windows service that would read all entries in the Application Event Log for that day. He pointed me to a link that used VBScript and some wacky dll named "winmgmnts". This seemed like a pain, and I was like...I know you can write to Event Logs with .NET, why couldn't you read them...sure enough, you can. The following code is used to read all entries for the current day of 3 defined logs. This, obviously, can be expanded further...which is what I intend to do.
using System;
using System.Diagnostics;
public class MyClass
{
public static void Main()
{
int month = DateTime.Today.Month;
int day = DateTime.Today.Day;
int year = DateTime.Today.Year;
string[] logNames = new string[] {"Application", "Security", "System"};
foreach(string log in logNames)
{
EventLog appLog = new EventLog(log);
foreach(EventLogEntry entry in appLog.Entries)
{
if(entry.TimeGenerated.Month == month && entry.TimeGenerated.Day == day && entry.TimeGenerated.Year == year)
{
Console.WriteLine("-----------------------------------------");
Console.WriteLine(entry.EntryType.ToString());
Console.WriteLine(entry.Message);
}
}
Console.ReadLine();
}
}
} -
Tab Key Emulation
Today, in the project I'm currently working on, I had to figure out a way of emulating the tab key by pressing the Enter key. I had found a very complicated script that required you to know the next id/name of the textbox or control that would need focus next...and since I'm creating 4+ textboxes in a datagrid, plus the ability of dynamic columns (all containing textboxes), this just wasn't going to be an easy task. As I set out, Google pointed me to a very helpful thread post. All you had to do is capture the enter key code and return the tab key code...simple, and works excellent!
-
Links 2004 Players?
Well I just purchased Links 2004 for the XBox yesterday, and the game is great. I know about a month ago, there was a lot of hoopla about .NET community geeks, like myself, were getting together regularly to play a few rounds. I unfortunately don't remember who you were, but if you want to add me to your friends list to catch me online playing sometime, my username is MHawley
-
BlogJet 1.0.0.15 Beta Released
BlogJet has released 1.0.0.15 Beta. Download it from here.
-
.NET Framework 1.1 SP1
I had downloaded XP SP2 Beta last night to install on my Virtual PC so I could try out Whidbey. Well, after I tried running the installer for Vault, I realized I didn't have the 1.1 framework installed, so the installation couldn't continue. I figured, why go re-download, when I know I have the .NET framework on the SP2 Beta CD. To my suprise, it installed the 1.1 framework, as well as SP1 for the 1.1 framework. Does anyone have any info pointing to the changelog for this SP? I'm intrigued to find out what was fixed.