Navigating with the Back button in Visual Studio

December 18, 2008

I have often wanted a Back button in Visual Studio, like there is in every browser. For instance if you right click some object and select “Go To Definition” then it would be nice to be able to jump back to where you where before without setting a bookmark or similar.

Turns out there actually are a back button, it’s just not accessible from the Edit menu, you just have to get the correct toolbar visible. To get it:

  • Right click on the toolbar (any button) and select “HTML source editing
  • The back button is the first button (looks like a document and a small blue arrow (Forward is here too)

To save monitor space, the “HTML source editing” can replace the “Text Editor” toolbar if you use keyboard shortcuts for bookmarks and intellisense.

The only minus is that apparently there are no keyboard shortcut for either Back or Forward button.

Update: There are shortcuts … CTRL+- for Back (I couldn’t get forward to work) or use navigation buttons on the mouse.

 


File upload with ASP.NET AJAX UpdatePanel

May 15, 2007

I’ve been working with the Microsoft AJAX toolkit recently (and not so much Windows Mobile – hence lack of update ūüôā . It’s an amazing framework for people who don’t know much JavaScript but still would like to do some AJAX style web programming¬†(like me). However since it involves a combination of .NET server side programming, HTML and client side JavaScript figuring out what’s wrong when something doesn’t work can be tricky. I’ll try to post a few tricks I found (mostly on ajax.asp.net ¬†ūüôā even though it’s not directly related to mobile programming.

The ASP.NET FileUpload¬†control doesn’t work within an AJAX UpdatePanel by default (when the upload button you create is inside the same panel). This is because a file cannot be uploaded asynchronously. To be able to upload a file the easiest solution is to make a complete postback when the user uploads a file. To do this add a PostBackTrigger on the button:

<asp:UpdatePanel> 
  <ContentTemplate> 
<asp:Button ID="ButtonUploadFile" 
    runat="server" Text="Upload" /> 
</ContentTemplate> 
  <Triggers> 
<asp:PostBackTrigger ControlID="ButtonUploadFile" /> 
  </Triggers> 
</asp:UpdatePanel>

(note that it is not an AsyncPostBackTrigger)


ActiveSync and Comodo Firewall

November 15, 2006

I recently installed the Comodo Firewall¬†since my old one Sygate FW has become obsolete, and although it seems quite nice and powerful there are some issues with it. One problem is that it often give false warnings about ‘parents’ (a program that launches another program), e.g. claiming that notepad tries to start Internet Explorer, when I have done it myself (this was a problem with Sygate too, but it actually seems worse here).

The other problem is that it seems to block quite a few things silently – for instance ActiveSync. To get¬†it to work I had to turn off the whole thing, which might be a bad idea if you are not behind a hardware firewall. Seems like it blocks the mobile device from getting an automatic IP or somesuch. You have to make a custom rule to get it to work. I suggest you change this rule a little to allow a IP range instead of just the one IP just in case.¬† I’ll repeat the walkthrough by Egemen here in case the URL goes missing:

( in Comodo: )
1- Go to “Security->Nework Montitor”,
2- Right click on the first rule(Rule Id = 0)
3- Select Add Rule->Add Before
4-¬† Action “Allow”, Protocol “TCP”, Direction “In”
5- Source IP : “Single IP” = “169.254.2.1”,
6- Remote IP : “Any”
6- Source Port : “Any”
8- Remote Port : “Any”
9- Click Ok button.

My alternative is to change step 5 so that you get 101 available IPs:
5-Source IP : “IP Range” = “169.254.2.0”¬† to “169.254.2.100”

Thanks to this I at least learned that there are more reserved IP ranges than the 192.168.x.x range, and that the 192.254.0.0 to 192.255.255.255 is reserved for “Automatic Private IP Addressing” – making this rule quite safe to install.

(To be fair there are some things that I really like with Comodo, for instance that you can disallow certain URL or IPs for each program, so that you can allow a program to access the Internet, but you can disallow it from calling home by banning the home IP only.)


Reinstalling Compact Framework 2.0

November 13, 2006

I recently did a hard reset on my device, but had problems installing CF2 because the installer complained that I already had installed it. (This seems like a bug to me – what if I had two Windows Mobile devices?)

Anyway, I didn’t want to uninstall then reinstall CF2 as suggested by the installer because I was afraid that it would mess up my settings and paths in Visual Studio.

To manually install CF2 just follow the instructions as for setting up the emulator Рi.e. install the file NETCFv2.wm.armv4i.cab.


Setting the emulator’s available RAM

July 9, 2006

It is useful to be able to change the Device emulators available RAM, however if you select File->Configure… in the emulator you are not able to change the values!

The supposed reason for this is that Windows Mobile does not support changing/adding RAM on the fly (if you put more RAM into your physical device, you have to restart it to be able to use it).

To change it: In Visual Studio, select Tools->Options…, then select Device Tools->Devices (You can also click Device Options on the Device toolbar). Select Windows Mobile 5.0 Pocket PC Emulator in the list to the left, and click Properties. Then click Emulator Options.
If you check the “Specify RAM size” checkbox, you are able to change the RAM (remember to restart the emulator!).

There are also some other important options here, I’ll come back to them later.

A final gotcha – if you have saved the emulator state any changes to the RAM will not be applied. You have to clear the saved state (in the emulator: File->Clear Saved State) and reset the Emulator for it to update.


Missing error messages

July 7, 2006

When debugging against a physical device you may get this message when breaking on an exception:
“An error message cannot be displayed because an optional resource assembly containing it cannot be found”.

It’s extremely annoying because it doesn’t tell you what ‘optional resource’ that is missing. Luckily I found a clue on the Microsoft Forums (link).

If you get this message you should try to install the file “System_SR_ENU_wm.CAB” from the Mobile 5.0 SDK (mine was at %program files%\Visual Studio 2005\SmartDevices\SDK\CompactFramework\2.0\v2.0\
WindowsCE\Diagnostics ).

Note that the ENU parts corresponds to English-US so if you have set a different locale on your device (Start->Settings->System tab->Regional Settings) you should chose the corresponding .CAB file (if your locale don’t have a CAB hopefully the ENU will work, although I haven’t tried it).

Also note that the file can be uninstalled as a normal program (Start->Settings->System tab->Remove Programs).

What’s bugging me is that it seems like this problem suddenly appeared (i.e. I got error messages before), and I don’t know why. Ah, well – as long as it works…

Edit: Tip – if it doesn’t work, try changing your locale to the language you installed. (Settings->System tab->Regional Settings)


Wait cursor

July 5, 2006

Getting the nice colorful system-is-busy hourglass (or whatever it is) to appear is extremely simple:

Cursor.Current = Cursors.WaitCursor;

Note that the animation will stay put until you change it back to Default, so it is a good idea to put it in a finally clause to make sure it happens:

try {
 Cursor.Current = Cursors.WaitCursor;
¬†//Do something time consuming…
}
finally {
 Cursor.Current = Cursors.Default;
}

In this way, even if you get an exception the cursor will switch back (this is a good idea for standard Windows Forms programming also btw)

Edit: The Cursor property is not on the form, but on System.Windows.Forms, changed the reference