Thursday, October 9, 2008

Debugging in Visual Studio in Firefox

I just found out how to make the Visual Studio to debug in Firefox:
1. Right-click on the file in the Solution Explorer
2. Select "Browse with"
3. In the dialog box select Firefox. If Firefox is not there, click Add and browse to the firefox.exe on your computer.
4. Click "Set as Default"

The next time you run the project it will be in Firefox. It's quite easy to switch between IE and Firefox. One thing I noticed is that while using Firefox, closing the browser window won't stop the debug mode, you have to use Shift + F5, or some toolbar/menu item that I can't find, to stop debugging.

Tuesday, October 7, 2008

the membership provider

For my latest project, I decided to try out the built in login/membership stuff that .NET provides. I am following these tutorials. So far it has been easy to follow and the built in stuff has a lot of stuff that is good from a security standpoint. I'll keep you posted!

Wednesday, September 24, 2008

ORDER BY in a view or a nested select statement

I noticed one different behavior in SQL Server 2005 comparing with 2000:

If you run “select * from (select top 100 percent * from [table name] order by lastname) as temp” on SqlServer 2000 and on SqlServer 2005, you will see the difference. In 2000, the list you get is still sorted while in 2005 it's not.

The bottomline is: don’t say “order by” in a view or in a nested select statement. Putting "order by" in a view is never a good practice, in my opinion, because:
1. You have to say "top 100 percent" in order to do that
2. We should put "order by" in the most outer select so it costs minimum workload for the Sql Server (it only needs to sort the things you need at the end).

Thursday, September 4, 2008

Form authentication with SSL

This is the settings we need in the Web.config:
<system.web>
<sessionState timeout="180" regenerateExpiredSessionId="false"/>
<authentication mode="Forms">
<forms name="XXX" loginUrl="login.aspx" protection="All" timeout="180" requireSSL="true"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<customErrors mode="RemoteOnly"/>
<compilation debug="false"></compilation>
</system.web>

Wednesday, August 27, 2008

DateTime ToString Formats

To format a DateTime:
string a = date.ToString("MM/dd/yyyy"); the string will look like "03/02/2008"

You can also do "MMM dd, yyyy", then you will have "Mar 02, 2008". For the entire list of format options, please see http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx.

Friday, August 22, 2008

toggleOptions

Hi guys!

Miss me? How can you miss me if I keep blogging! :P

OK so as you know I added a code library to the repo. I put all the Javascript we had already collected into it. The trouble is it's disorganized and some of it is pretty old and possible inefficient or not the best code. Therefore I hope to clean up the library to only have clean and good code :) And in an effort to do this AND organzie, from now on when I can I will add scripts into subfolders. I will label the folders by control type. Then inside the folder will be all the different scripts. So, if the JS is in a subfolder of Javascript, then it has been "quality controlled."

Please feel free to aid my efforts! Remember when you add a script to add a comment with your initials so we know who to ask if we have questions about the code!

Myself, I will try to blog whenever I add a script.

OK on to today's script. We may already have had something like this, I don't know. It was a mess in there so I didn't find it.

This function was written for those times when one of the options you pick should make all of the other options invalid. For example let's say the question is What color do you like best: red, green or none of the above? None of the above should obviously make it impossible to check red or green.

The code below is specifically for ASP:CheckBoxList, hence the part where I format the field's name as name = fieldName + "_" + i; because .NET takes the ListItem in a CheckBoxList and names it controlId_indexOfItem. If in my example the control was called cblColor then in the HTML red would have the id cblColor_0, and green would be cblColor_1 etc etc.

The parameters: optionToFocusOn is the one that triggers the function. In my example it would be cblColor_2, the none of the above. totalOptions is the total number of options, and in my example would be 3. fieldName would be the id of the control itself; in my example it would be cblColor.


//toggle options on and off - for use when one selection should disable the rest of the group
//for use with the ASP:CheckBoxList

function toggleOptions (optionToFocusOn, totalOptions, fieldName)
{
var name = fieldName + "_" + optionToFocusOn;
if (document.getElementById(name).checked == true)
{
for (i = 0; i < totalOptions; i++)
{
name = fieldName + "_" + i;
if (i != optionToFocusOn)
{
document.getElementById(name).checked = false;
document.getElementById(name).disabled = true;
}
}
}
else
{
for (i = 0; i < totalOptions; i++)
{
name = fieldName + "_" + i;
if (i != optionToFocusOn)
{
document.getElementById(name).disabled = false;
}
}
}
}

Thursday, July 24, 2008

document.form1 doesn't work?

In an aspx page, we use two ways to call a form from javascript:
1. document.getElementById("form1"), or
2. document.form1
and they both work.

However, the "form1" means different things in these two lines:
1. document.getElementById("form1") -- the form1 is the id of the form
2. document.form1 -- the form1 is the name of the form

When working on an aspx page, we only put id="form1" in the form tag, but when the page gets processed and sent back to the client, ASP.NET adds a bunch of stuff to the page, including name="form1" in the form tag (it puts a name in every server control in a page). So that is why document.form1 works in an aspx page without a name for the form.

If you works on an html page, you will have to put name="form1" to get the second method to work.