December 2006 - Posts

ASP.NET 2.0 – Mutex cannot create and Weird web outputs

If you face 2 scenarios as below:

 

1st scenario:

 

When you run your web application and you find out that you have an error Mutex cannot create error (InvalidException something like that), what should you do?

 

2nd scenario:

 

When you create a new web application project in Visual Studio 2005, then you drag 2 controls (button and textbox) into your web form. Later you try to run it and you cannot see any controls on your web form, what should you do?

 

Very simple. I learned something today while helping to fix my colleague’s development machine. Do this:

 

a)       Close your Visual Studio 2005 IDE.

b)       Go to this folder C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

c)       Delete all the files within that directory

d)       Then reset your IIS by typing this in the Start à Run “iisreset”

e)       Try running your web project inside Visual Studio 2005 IDE and rebuild that project

 

Trust me it will work J have fun.

Posted by chuawenching with no comments

ASP.NET 2.0 SetFocus to control

Back in ASP.NET 1.1, you have to use javascript to set focus on a particular control in the page (correct me if I am wrong). But in ASP.NET 2.0, things are so much easier.

 

Just code this:

 

Page.SetFocus(btnProjectSave);

 

The SetFocus method accepts 1 parameter which is the Control (dropdownlist, button, textboxt, etc)

 

Enjoy

Posted by chuawenching with no comments

ASP.NET 2.0 – Move the cursor from 1 textbox to the other automatically

Assuming you have this simple scenario (normally apply to phone number or personal identification card number). You have a phone number. Normally the phone number is broken into 2 sections. The 1st section is the country code say 60 (Malaysia). And the other section is for your numbers assigned to you say (9988 0011). You can do this in 1 textbox for sure, but your boss wants some fancy. He/she asks you to break into 2 textboxes. Assuming you have entered 60 in the 1st textbox, when you press the 3rd character which is 9 it will move the cursor automatically into the 2nd textbox.

 

I am using the JavaScript way. Thanks to a few people who recommends me this way. Just take note, by default when you create a textbox in Visual Studio 2005, there is no onKeyPress event in the intellisense. So you have to manually inject the code like this below:

 

TextBox1.Attributes.Add("onKeyPress", "return Length_TextField_Validator()");

 

Simple right. Basically Length_TextField_Validator() is a JavaScript function in the html code.

 

Below is the sample code.

 

Default.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Untitled Page</title>

 

    <script language="javascript">   

        <!--

            // Check the length of the textbox

            function Length_TextField_Validator()

            {

                if ((form_name.TextBox1.value.length > 2))

                {               

                    form_name.TextBox2.focus();

 

                    return (false);

                }

 

                return (true);

            }

        -->

    </script>

 

</head>

<body>

    <form id="form_name" runat="server">

        <div>

            ASP.NET version<br />

            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

        </div>

    </form>

</body>

</html>

 

Default.aspx.cs

 

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        // Since by default, asp.net 2.0 textbox does not have the onKeyPress event

        // through intellisense, you have to do this way :P

        TextBox1.Attributes.Add("onKeyPress", "return Length_TextField_Validator()");

    }

}

 

Have fun J

Posted by chuawenching with no comments

How to view Office 2007 file formats using Office 2003?

Hi,

I got the speaker evaluations from Alvin and since I did not have Office 2007 in my laptop, I was not able to view it. I tried to email him but probably he was not at his machine or busy. So I decided to research for viewers or conversions.

Finally I found this http://www.microsoft.com/downloads/details.aspx?familyid=941B3470-3AE9-4AEE-8F43-C6BB74CD1466&displaylang=en

This is really cool ... check this UI on how you can open an excel 2007 in office 2003, just right click on the file and choose this http://community.sgdotnet.org/photos/chuawenching/picture62530.aspx

Have fun :)

Posted by chuawenching with no comments

Internet in Malaysia is quite bad

I had been facing internet problems since yesterday. Until 6.00 p.m. today, things are getting much better, e.g. I could access my yahoo email, accessing into google and Microsoft sites. Thanks :)

I just can't live without Internet :)

Posted by chuawenching with no comments

My Singapore Trip - especially Singapore DevCon 2006

Thanks to the SgDotNet team especially Wee Hyong and Alvin for giving me an opportunity to speak in this event. I was so grateful for these people. I was honor to speak with other top notch speakers in Singapore.

 

It seemed that my presentation had improved a lot. Thanks for the feedback Wee Hyong and Wilson. I will keep on improving and speak more.

 

http://community.sgdotnet.org/photos/chuawenching/picture58798.aspx

 

http://community.sgdotnet.org/photos/chuawenching/picture58800.aspx

 

I met 2 pretty girls in this event. One was at the counter, heard she was a MSP. Other one was the super duper highly educated girl who couldn’t spell “Backpack”. Haha. Just kidding. Anyway I couldn’t remember her name, but she was very good in foosball …

 

Other than that, I stayed at my friend’s place in Yishun. It was so far away from the shopping malls. I was exhausted for walking in Singapore. Haha.

 

I spend quite a lot of money in 2 days times. RM 780.00 gone with the wind.

 

I hope to speak in Singapore DevCon again next time. Next, waiting for approval on my talk somewhere on January in Sarawak. I hope to get funding for this one J

Posted by chuawenching with no comments
Filed under:

ASP.NET 2.0 button CausesValidation=false

Thanks to my colleague. I did not know until today. For example you have 1 RequiredFieldValidator for your textbox. Assuming there is no value in this textbox, but you want to press the close button. By default you can’t as it will prompt you a message in the ValidationSummary to enter this value. So when you set the property of the button CausesValidation=false, it will ignore the validation.

 

<asp:Button ID="btnClose" CausesValidation=false runat="server" Text="Close" Width="64px" CssClass="buttonStyle" OnClick="btnClose_Click" />

 

Cool. Save my day J

Posted by chuawenching with no comments

ASP.NET 2.0 DataView - Select by DISTINCT

Assuming you has this scenario. 2 DataTable(s) which you grabbed data from the database. Then you will merge the DataTable1 to DataTable2 within your Business Rule class.

 

Example,

 

dTable1.Merge(dTable2);

 

Now you will noticed that there are 2 rows of data which have similar data. You are curious on how you can select a distinct from these DataTable so it will not show duplicate data. You do not plan to rely on stored proc to handle this.

 

You can do select statement with DataTable, however it is not possible with DISTINCT. So for my case, I have use DataView instead to do the DISTINCT and then cast it to a DataTable like this:

 

DataTable dTest = dView.ToTable(true, "ResearchID", "ResearchTitle", "ConsultantID", "ConsultantName", "StartDate", "EndDate");

 

Just take note, the argument 2 onwards are your columns. You have to put all your columns here. Assuming originally your data inside your DataTable has 5 columns, you have to put all 5 columns here.

 

Cheers.

Posted by chuawenching with 1 comment(s)

ASP.NET 1.1 to ASP.NET 2.0 Migration #14 - Naming Conflicts

This happens a lot of times in Visual Studio 2005 than Visual Studio .NET 2003. The reason is whenever you create a new web form or class; it will not create a namespace for you. So when you try to build a project or even trying to merge it into a single assembly, you will see a lot of problems on this.

 

I believe a good practice is to put your class or web forms into a namespace. I am curious what makes Microsoft not to have namespace in their class?

Posted by chuawenching with no comments

Visual Studio 2005: Is it smart enough?

It had been my worst nightmare on migrating an existing Visual Studio .NET 2002 projects to 2005. I had 1 solution which consisted of 7 projects. There are 2 web projects and the other five are class libraries.

 

In one of the Project “ABC”, it contains a lot of folders and then sub folders.

 

Assuming this:

 

ABC

à A à A.1, A.2, A.3

à B à B.1, B.2, B3, B4

à C à C1, C2, C3, C4, C5, C6, C7, C8

à D à D1, D2

à E à E1

à F à F1, F2, F3

 

 I tried to build the project itself and in the output window it only shows that it builds up to C à C1, C2, and C3.

 

It does not build the other folders and sub folders. Furthermore it doesn’t show any build or warning errors. Just build succeeded. Weird right?

 

So I believe that Visual Studio 2005 is not smart after all. Later I found out that C4 sub folder was causing the problem. Once remove that folder, I can build other folders without any problem. Apparently in C4, there are errors building individual pages. Weird? Why can’t Visual Studio 2005 capture this?

Posted by chuawenching with no comments

Visual Studio 2005: Finds bugs that do not appear in Build/Compile

I just found out about this too. I never had errors or warnings on my web applications. Apparently, my web application builds fine. When you try to publish it, it will work fine.

 

This surprises me sometimes that while running my web application, it will show me errors which at first I thought it could be a run time bug (mostly on logics or data type not handled properly).

 

Some day ago, I found out about Web Deployment Package (WDP) by Microsoft. It is an add-in to your current Visual Studio 2005. The reason why WDP is developed by Microsoft is for developers to deploy web applications projects like the old days Visual Studio .NET 2003 (correct me if I am wrong).

 

With WDP you can build release mode of pre-compiled web application easily even though I do admit it is very slow L

 

These 2 options are by default – “Allow this precompiled site to be updateable” and “Merge all outputs into a single assembly”.

 

Basically when you build this deployment package, it will do a couple of process. The 2 things that I had noticed the most are aspnet_compiler and asp_merge.

 

From these 2 tools, you will find out that whether your web application really consists any bugs/errors which are ignored when you build your web application (F6).

 

Give it a try and you will know what I mean. Anyway if you are not deploying anything, it will be good for you to install this.

Posted by chuawenching with no comments

Building Security Awareness in Web Application #1: Why JavaScript is so powerful?

A lot of people told me about the danger of JavaScript like you can inject JavaScript into textbox (Cross Site Scripting). But I never know you can do this:

 

Taking an example:

 

Type this in your Internet Explorer: http://www.mind.com.my

 

When the page finishes loading, type this instead:

"javascript" : document.body.contentEditable='true'; document.designMode = 'on'; void 0

 

*remove the quotes in between javascript. The colon : should stick together at the right side of javascript word. 

 

You will be surprised that you can remove the controls used within this page up until clearing into a blank white site.

 

This way is meant for script kiddies and show off to their girl friend.

 

More to come.

 

*Take note; this way cannot works on flash web application. I had tried a few, and I believed you couldn’t remove the flash from the site.

Posted by chuawenching with no comments

Building Security Awareness in Web Application Series

Introduction

 

I do not have the time to write articles like I did back in year 2004. So does it mean that Building Security Awareness in .NET Application is a closed down. I can say it is and I will not continue write anything that does not relates to my work or career. Instead I plan to write blogs that relates to the topics that interests me.

 

Starting from today, I will be blogging on this “Building Security Awareness in Web Application”. Why only Web Application? First I had started to love building web application using ASP.NET technology? Second, I am a full time ASP.NET Developer. Third, I have a lot of interests in learning ways to protect the web applications that I am developing now and future. Instead of long articles, I will be blogging it. It will be easier for me and not relying on an editor to edit my articles.

 

Honestly speaking, I will be sharing on what I have learned. It is meant for educational purposes only. If you find that I have a wrong concept, do highlight to me and correct me. I will love to learn and improve myself in this topic “Security” and “Building more robust web applications for my customers”.

 

Lastly, of course I will still be blogging on ASP.NET 1.1 to 2.0 migrations tips and others that I find interesting.

 

Thank you.

Posted by chuawenching with no comments

MessenPass - discover your msn, gtalk, yahoo password

My gosh, this is powerful http://www.nirsoft.net/utils/mspass.html 

I learned this from youtube. If you able to access your colleague's machine, you can get all the password so easily. Be careful on this one. Killing software.

Posted by chuawenching with 4 comment(s)
Filed under:
More Posts Next page »