Information Dynamics
BLOG.INFORMATIONDYNAMICS.US

Visual Studio Toolbox items greyed out

Got a little exuberant using Add-Ins in Visual Studio. Not sure which
add-in caused the probem. To remedy the situation I:
1) shut down Visual Studio
2)went to (on XP) C:\Documents and Settings\dklug\Local
Settings\Application Data\Microsoft\VisualStudio\10.0 and deleted the tdb
files.
3)restart VS and right click in the toolbox section> choose Show All

Serialization

For many complex objects, such as those that make extensive use of
references ,
this process is not straightforward. Serialization of object-oriented
objects does
not include any of their associated
methodswith
which they were previously inextricably linked. This process of
serializing an object is also called *deflating* or
*marshalling
* an object.



Silverlight graphic

http://charlespetzold.com/silverlight/LissajousCurves/LissajousCurves.html

HTML5

Tags
http://html5tutorial.net/html-5-reference/html-5-reference.html

C# HTML5

"exceeding complexity budget as a language"
http://html5tutorial.net/

Free Web Services and Database

Amazon Web Services (AWS) was one of the results, however, without a clear
explanation of what you would end up paying for, I am not interested.

This is a list of free web services available, including Maps from USGS,
Stock Prices, Location based functionality, weather and credit card
verification

http://www.wsdll.com/Search.aspx

This is a database of Federal Spending (limited to 1000 records a download)
http://www.fedspending.org/devel/

Books to read

http://stackoverflow.com/questions/1711/what-is-the-single-most-influential-book-every-programmer-should-read


- O'Reilly's Open Books Project

http://oreilly.com/openbook/


- Free Tech Books

Don't overlook the languages section along the left hand side...

http://www.freetechbooks.com/

ASP.NET some little used tips and tricks

*While testing*, you can have emails sent to a folder on your computer
instead of an SMTP server. Put this in your web.config:










*HttpContext.Current* always gives you access to the current context's
Request/Response/etc., even when you don't have access to the Page's
properties (e.g., from a loosely-coupled helper class).

*You can continue* executing code on the same page after redirecting the
user to another one by calling Response.Redirect(url, false )

*You don't need .ASPX files* if all you want is a compiled Page (or any
IHttpHandler). Just set the path and HTTP methods to point to the class in
the element in the web.config file.

*A Page object can be retrieved *from an .ASPX file programmatically by
calling PageParser.GetCompiledPageInstance(virtualPath,aspxFileName,Context)


*Add this* to your web.config for much faster compilation (post 3.5SP1).



*Retail mode* at the machine.config level:







This overrides the web.config settings to enforce debug to false, turns
custom errors on and disables tracing. No more forgetting to change
attributes before publishing - just leave them all configured for
development or test environments and update the production retail
setting. Of course, you still want to build in Release mode.

*You can use:*

Request.Params[Control.UniqueId]
To get the value of a control before viewstate is initialized (Control.Text
etc will be empty at this point). This is useful for code in Init.


*You can use ASP.NET AJAX callbacks* to web methods placed in ASPX pages.
You can decorate a static method with the [WebMethod()] and
[ScriptMethod()] attributes. For example:

[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static List GetFruitBeginingWith(string letter)
{
List products = new List()
{
"Apple", "Banana", "Blackberry", "Blueberries", "Orange",
"Mango", "Melon", "Peach"
};

return products.Where(p => p.StartsWith(letter)).ToList();
}

Now, in your ASPX page you can do this:



EnablePageMethods="true" />
/>


And call your server side method via JavaScript using:




*Check to see if the client is still connected*, before starting a
long-running task:

if (this.Response.IsClientConnected)
{
// long-running task
}


*Tag Mapping:*
Tag mapping allows you to swap compatible controls at compile time on every
page in your web application. A useful example is if you have a stock
ASP.NET control, such as a DropDownList, and you want to replace it with a
customized control that is derived from DropDownList. This could be a
control that has been customized to provide more optimized caching of
lookup data. Instead of editing every web form and replacing the built in
DropDownLists with your custom version, you can have ASP.NET in effect do
it for you by modifying web.config:




mappedTagType="SmartDropDown"/>




*You can use ASP.NET Comments* within an .aspx page to comment out full
parts of a page including server controls. And the contents that is
commented out will never be sent to the client.

<%--



--%>

*The Code Expression Builder*
Sample markup:

Text = '<%$ Code: GetText() %>'
Text = '<%$ Code: MyStaticClass.MyStaticProperty %>'
Text = '<%$ Code: DateTime.Now.ToShortDateString() %>'
MaxLenth = '<%$ Code: 30 + 40 %>'
The real beauty of the code expression builder is that you can use
databinding like expressions in non-databinding situations. You can also
create other Expression Builders that perform other functions.

web.config:





The cs class that makes it all happen:

[ExpressionPrefix("Code")]
public class CodeExpressionBuilder : ExpressionBuilder
{
public override CodeExpression GetCodeExpression(
BoundPropertyEntry entry,
object parsedData,
ExpressionBuilderContext context)
{
return new CodeSnippetExpression(entry.Expression);
}
}



*IsDebuggingEnabled:*

HttpContext.Current.IsDebuggingEnabled

This is great for determining which scripts to output (min or full
versions) or anything else you might want in dev, but not in production.


*MaintainScrollPositionOnPostBack:*

MaintainScrollPositionOnPostback attribute in the @Page directive. It is
used to maintain scroll position of an aspx page across postbacks.

*R**un ASP.Net outside of IIS or Visual Studio**:*

The whole runtime is packaged up and ready to be hosted in any process that
wants to give it a try. Using ApplicationHost, HttpRuntime and
HttpApplication classes, you too can grind up those .aspx pages and get
shiny HTML output from them.

HostingClass host =
ApplicationHost.CreateApplicationHost(typeof(HostingClass),
"/virtualpath", "physicalPath");
host.ProcessPage(urlToAspxFile);
And your hosting class:

public class HostingClass : MarshalByRefObject
{
public void ProcessPage(string url)
{
using (StreamWriter sw = new StreamWriter("C:\temp.html"))
{
SimpleWorkerRequest worker = new SimpleWorkerRequest(url, null,
sw);
HttpRuntime.ProcessRequest(worker);
}

}
}



*Request.IsLocal Property:*

It indicates whether current request is coming from Local Computer or not.

if( Request.IsLocal )
{
LoadLocalAdminMailSettings();
}
else
{
LoadServerAdminMailSettings();
}


*By default web form page inherits from System.Web.UI.Page class*. There is
a way to constraint any page to inherit from a base class. Simply add a new
line on your web.config:




Geo location through the browser

Here is the page-level script code to do this:







The first script uses Google's gears object (used in Chrome, for
example) which stores the browser's geolocation information. The second
script is an implementation that looks for different device types and
handles the "quirks". The inline third script simply implements all the
above and populates two hidden fields with the latitude and longitude.
Since I am using the Artem.GoogleMap server control in this case, we have
to trigger a postback to get the control to render a map.

Now what if none of this works? Let's have a look at the ASP.NET page
codebehind:

protected void Page_Load(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(Lat.Value) &&
!String.IsNullOrEmpty(Lng.Value))
{
double latitude = double.Parse(Lat.Value);
double longitude = double.Parse(Lng.Value);
var request = new GeoRequest(latitude, longitude);
var response = request.GetResponse();
if (response.Status == GeoStatus.OK)
{
FormattedAdr.Text =
response.Results[0].FormattedAddress;
map1.Address = FormattedAdr.Text;
}
}

else
{
var loc = GEOIP.GeoLocation.GetLocation();
map1.Latitude = loc.Latitude;
map1.Longitude = loc.Longitude;
FormattedAdr.Text = loc.City + " " + loc.Region + " " +
loc.PostalCode;
map1.DataBind();
}
}

You can see above that if the hidden fields are not empty, we issue a
GoogleGeocoding request and map the coordinates. And, if that fails, I use
the free MaxMind Geolocation javascript API, but I do this server-side as
follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace GEOIP
{
public static class GeoLocation
{

public static Location GetLocation()
{
try
{
WebClient wc = new WebClient();
string s = wc.DownloadString("
http://j.maxmind.com/app/geoip.js");
wc.Dispose();
/* SAMPLE
function geoip_country_code() { return 'US'; }
function geoip_country_name() { return 'United States'; }
function geoip_city() { return 'Deland'; }
function geoip_region() { return 'FL'; }
function geoip_region_name() { return 'Florida'; }
function geoip_latitude() { return '29.0575'; }
function geoip_longitude() { return '-81.3344'; }
function geoip_postal_code() { return ''; }
function geoip_area_code() { return '386'; }
function geoip_metro_code() { return '534'; } */

s = s.Replace("function geoip_country_code() { return '", ""
);
s = s.Replace("function geoip_country_name() { return '", ""
);
s = s.Replace("function geoip_city() { return '", ""
);
s = s.Replace("function geoip_region() { return '", ""
);
s = s.Replace("function geoip_region_name() { return '", ""
);
s = s.Replace("function geoip_latitude() { return '", ""
);
s = s.Replace("function geoip_longitude() { return '", ""
);
s = s.Replace("function geoip_postal_code() { return '", ""
);
s = s.Replace("function geoip_area_code() { return '", ""
);
s = s.Replace("function geoip_metro_code() { return '", ""
);
s = s.Replace("'; }", "");
string[] s2 = s.Split("
".ToCharArray());


Location loc = new Location();
loc.CountryCode = s2[0];
loc.CountryName = s2[1];
loc.City = s2[2];
loc.Region = s2[3];
loc.RegionName = s2[4];
loc.Latitude = double.Parse(s2[5]);
loc.Longitude = double.Parse(s2[6]);
loc.PostalCode = s2[7];
loc.AreaCode = s2[8];
loc.MetroCode = s2[9];
return loc;
}
catch
{
return null;
}
}
}
}

public class Location
{
public string CountryCode { get; set; }
public string CountryName { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string RegionName { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public string PostalCode { get; set; }
public string AreaCode { get; set; }
public string MetroCode { get; set; }

}

The result is that we can get a map for virtually any browser or device.

http://eggheadcafe.com/FileUpload/1145921998_GeoLocation.zip

Transferring Page Date - 8 ways

*1. Use the querystring:*

protected void QueryStringButton_Click(object sender, EventArgs e)
{
Response.Redirect("QueryStringPage.aspx?Data=" +
Server.UrlEncode(DataToSendTextBox.Text));
}
*
**2. Use HTTP POST:*

PostBackUrl="~/HttpPostPage.aspx" onclick
="HttpPostButton_Click"/>

protected void HttpPostButton_Click(object sender, EventArgs e)
{
// The PostBackUrl property of the Button takes care of where to send
it!
}

* 3. Use Session State:*

protected void SessionStateButton_Click(object sender, EventArgs e)
{
Session["Data"] = DataToSendTextBox.Text;
Response.Redirect("SessionStatePage.aspx");
}

*4. Use public properties:*

public string DataToSend
{
get
{
return DataToSendTextBox.Text;
}
}

protected void PublicPropertiesButton_Click(object sender,
EventArgs e)
{
Server.Transfer("PublicPropertiesPage.aspx");
}

*5. Use PreviousPage Control Info:*

protected void ControlInfoButton_Click(object sender, EventArgs e)
{
Server.Transfer("ControlInfoPage.aspx");
}

// target page:
protected void Page_Load(object sender, EventArgs e)
{
var textbox =
PreviousPage.FindControl("DataToSendTextbox") asTextBox;
if (textbox != null)
{
DataReceivedLabel.Text = textbox.Text;
}
}

*6. Use HttpContext Items Collection:*

protected void HttpContextButton_Click(object sender, EventArgs e)
{
HttpContext.Current.Items["data"] = DataToSendTextBox.Text;
Server.Transfer("HttpContextItemsPage.aspx");
}

// target page:
protected void Page_Load(object sender, EventArgs e)
{
this.DataReceivedLabel.Text =(String) HttpContext.Current
..Items["data"];
}

*7. Use Cookies:*

protected void CookiesButton_Click(object sender, EventArgs e)
{
HttpCookie cook = new HttpCookie("data");
cook.Expires = DateTime.Now.AddDays(1);
cook.Value = DataToSendTextBox.Text;
Response.Cookies.Add(cook);
Response.Redirect("HttpCookiePage.aspx");
}

// target page:
protected void Page_Load(object sender, EventArgs e)
{
DataReceivedLabel.Text = Request.Cookies["data"].Value;
}

*8. Use Cache:*

protected void CacheButton_Click(object sender, EventArgs e)
{
Cache["data"] = DataToSendTextBox.Text;
Server.Transfer("CachePage.aspx");
}
// target page:
protected void Page_Load(object sender, EventArgs e)
{
this.DataReceivedLabel.Text = (string) Cache["data"];
}

Calendar

January 2012
SuMoTuWeThFrSa
1234567
891011121314
15161718192021
22232425262728
293031

Monthly Archives

Recent Posts

  1. Visual Studio Toolbox items greyed out
    Friday, January 27, 2012
  2. Serialization
    Friday, January 13, 2012
  3. Silverlight graphic
    Thursday, January 12, 2012
  4. HTML5
    Wednesday, January 11, 2012
  5. C# HTML5
    Wednesday, January 11, 2012
  6. Free Web Services and Database
    Tuesday, January 10, 2012
  7. Books to read
    Thursday, January 05, 2012
  8. ASP.NET some little used tips and tricks
    Tuesday, January 03, 2012
  9. Geo location through the browser
    Tuesday, January 03, 2012
  10. Transferring Page Date - 8 ways
    Tuesday, January 03, 2012

Recent Comments

  1. Deb on Silverlight graphic
    1/12/2012
  2. Deb on Silverlight graphic
    1/12/2012
  3. Deb on Silverlight graphic
    1/12/2012
  4. James on HTML editor
    5/4/2011
  5. Deb on HTML editor
    1/30/2009

Subscribe


Tag Cloud