Monday, March 9, 2009

Missing arrows on Menu Server Control in ASP.NET

Essentially this issue has to do with the mapping for the ".axd" extension in IIS.

You must:
  1. Make sure that the ".axd" extension is mapped to the aspnet_isapi.dll executable
  2. Make sure "Verify that file exists" is NOT checked
The reason you need this?

The axd extension is used for the WebResource.axd calls that are inserted into your markup when the page is rendered. The WebResource.axd page doesn't exist but is dealt with in a sepecial way by the runtime.

The Menu control required JavaScript and the little arrow that you see missing on the Menu control. these resources are stored in an Assembly. The WebResource.axd extension mapping was created to allow access to these resources from the client side.

So when the Menu control is rendering, a WebResource.axd call is inserted into the markup and when the browser is processing it it will call the WebResource.axd page(Yes i know it doesn't exist.) to retrieve the resource...

Saturday, October 25, 2008

Sqlite - Get last inserted identity value

This took me about 2 hours to find... I can't believe how hard this really simple thing was to find... I'm really only familiar with Sql Server 2002 & 2005 so I couldn't use the normal SELECT @@IDENTITY option.

The question is: How do i get the identity value of the last inserted row in Sqlite?

Answer:

SELECT last_insert_rowid();

That's it!

Now, try not forget it! :-)

The curse of the Dreaded Session... or something!

The previous attempt at PHP was on a Windows system, now I'm on a Ubuntu (Hardy) laptop, and I had a little issue with getting the session to work... And had trouble finding the solution... The warnings I got were the following...

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/Justin/Experimentation/MyPage.php:8) in /var/www/Justin/Experimentation/MyPage.php on line 8

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/Justin/Experimentation/MyPage.php:8) in /var/www/Justin/Experimentation/MyPage.php on line 8

Here is a simple version of what caused the error:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<?php session_start(); ?>


Now the warning message said "Cannot send session cache limiter - headers already sent".

I'm going to hazard a quess as to how PHP's page processing model works...
  1. The processor starts processing the file. Any PHP code is processed.
  2. When it gets to the first bit of HTML (in this case the DOCTYPE) the header information is sent to the client browser
  3. The rest of the page is processed as per normal

Update:
I found out later that this is essentially correct. Any output like a blank line or output from php code will cause the Http headers to be sent to the user agent: See here


Sessions usually work by sending a cookie to the client (user agent) so that the server can keep track of which session relates to which user agent.

Now the session_start() call is "after" the first bit of Html, the headers have therefore already been sent, and we get this warning... and a non-functional session!

The Rule
Any time you need to manipulate the header information or any time you "do" anything that itself manipulates the header information, you need to execute the PHP code BEFORE ANY Html on the page!

So you would do this:

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

Then, of course, the session will be started, the session cookie added to the header information, then the first bit of Html is hit and off goes your cookie to the user agent(browser)

So simple... So annoying to figure out... I better remember this on! I'm going to need it!

Thursday, October 23, 2008

AutoCompleteType and Autocomplete

In this post I hope to give simple examples of how to use the AutoCompleteType and autocomplete attributes in both Html and ASP.NET, and also clear up some of the not so obvious things that I've found while learning how this simple but useful feature works.

Now this is, in theory, quite a simple topic. In practice not everything is especially in programming... The number of times that something has seemed simple but has elicited many "why is this not working.... this is SOOO simple" responses is ridiculous!

The Auto Completion Feature
How many people user the Auto Complete feature in their browser? Anyone? If your not sure what I'm talking about I'm referring to that drop down box that sometimes comes up below text boxes when you are entering your email address or phone number for example.

Web developers can specify that a particular text box should have an email entered into it. When the form is posted the value in the text box will be stored. When you go to another text box that specifies that a text box should have an email entered into it and the user starts typing an email address that they have entered previously, that previously entered email address will show in a drop down sort of box underneath the text box in question.

Hint: The data is only stored only after a postback from a submit button. (LinkButtons in ASP.NET Seem to not work! :,( What a pain!)

It can be very handy.... or very annoying. I turned it off on my browser at work. Then i used the AutoCompleteType feature and it didn't work... :-)

AutoCompleteType
In ASP.NET 2.0, the TextBox control has an AutoCompleteType attribute/property. There are a variety of options for this property which can be found here.

<asp:TextBox id="txtEmailAddress" runat="server" AutoCompleteType="Email" />

ASP.NET renders "
vcard_name" attribute on the "input" element that is rendered by the TextBox. The value specified will associate the content (for example an email address) with a list of items of that type somewhere in the brains of the browser (or wherever!)

Hint: For probably every other browser other than IE you will not see a "vcard_name" attribute rendered. The ASP.NET framework consults the ".browser" files for the particular browser requesting the page.
The "Default.browser" file specifies "supportsVCard" as false and IE specific ".browser" file sets it to true. Firefox defaults to false, and therefore I take it that this means that Firefox doesn't support the "vcard_name" attribute. Never-the-less, autocomplete still works in Firefox, just in a different manner!

Posting a Form & An issue with ASP.NET
As already stated, any data that can be stored for use by the auto complete feature will be stored when a submit button is pressed.

In ASP.NET you may come across the issue where you have a form which posts back using a LinkButton. In this case the browser will NOT store the autocomplete information.

TODO: I have only tested this with IE. Am not sure whether other browsers have this issue.

Textbox Autocomplete
The
above link goes to a thread that has information on how to solve the above issue... I haven't tried it personally though it may be useful to someone!

Input Autocomplete Element
This attribute simply applies to the input element.

<input id="txtEmail" type="text" name="txtEmailAddress" autocomplete="on" />

Hint: You MUST give the input element a name attribute, otherwise autocomplete will not work.
Hint: The name that you give an element is used by the browser to provide autocomplete for elements with the same value. In other words. If you have an input field with a name of "email" and you have entered your name a few times into that field. Then you go to another page that also has an input field with a name of "email" then you will (probably) get a drop down box showing the email address entered on the other page.

Turning off auto completion
You know you can turn autocomplete "on" :-) ... but did you know...

Turn off an individual element
You can turn autocomplete off on individual elements like so:

<input id="txtEmail" name="email" autocomplete="off" type="text" />

Turn of autocomplete for a whole form
By putting an autocomplete="off" attribute on the form element you can turn off the auto completion feature. This will turn auto completion off even on any ASP.NET form controls.

<form autocomplete="off">
:
</form>


Browser Settings
Now, how to turn the setting on and off in a browser.

Internet Explorer:
IE was not showing the lovely drop down box when I first experimented with this feature... Why? Because I had turned it off because I found it annoying (other web developers might understand due to the amount of garbage we put into textboxes sometimes)

Now. How to enable it:
  1. Tools | Internet Options
  2. Select the "Content" tab
  3. In the "AutoComplete" section click the "Settings" button
  4. Make sure the "Forms" checkbox is checked
I hope this is thorough enough and hopefully useful to someone!

FireFox 3
  1. Edit | Preferences...
  2. Click the Privacy Tab
  3. Make sure the "Remember what I enter in forms and the search bar" is checked
Hope you don't forget this! :o)

Wednesday, October 22, 2008

ASP.NET Ajax Debug using Trace

OK! Blogging is annoying, because I've got about 6 posts partially done because of all the idea's today...

This one is nice and simple for my first real posts so I will post it.

Found this nice bit of information on how to do a trace using ASP.NET AJAX's Sys.Debug.trace() JavaScript function... Found it here.

Below I've tried to provide a barebones example to show how it works.

If you are using ASP.NET 2.0 then you will need to install ASP.NET AJAX first. Instructions are here and to download go here. If you have ASP.NET 3.5 installed they you can just put the code into a form and it will work.

Rules
The id of the TextArea control needs to be "TraceConsole". All trace information goes to the TextArea with this id and this id only!

Example:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<textarea id="TraceConsole" style="height: 500px; width: 500px">
</textarea>

<script language="javascript" type="text/javascript">
function TraceSomething() {
Sys.Debug.trace("To trace or not to trace...");
Sys.Debug.trace("... that is the question!");
}

TraceSomething();
</script>
Resources:

Introduction

Ok, It's after work and it's time to make this first entry a little more... interesting! Compared to what it was!

I'm a programmer and work for a company that develops an ASP.NET 2.0 application. I also like dabbling in php, though I'm very much a beginner. I program in VB though i started of in C# and still do programming in C# on Mono at home...

My home computer is an Asus running Ubuntu 8.04 and I also have another older computer running Fedora 9 (I think... or is it 8?) and Windows XP in a duel boot configuration.... regardless of this extra computer it basically doesn't get turned on :o)

This blog will be about those things that I've found out that I find to be useful but especially where it is something that is easy to forget. It will mainly deal with ASP.NET in VB as that is what i work in, though I will probably add stuff from other interests also like PHP of Mono specific stuff!

I hope that if anyone ever decides to read this blog that they will find the information somewhat useful!

Regard

Me!