Posted by ken zheng on August 27, 2008
The .NET Framework 3.5 Enhancements Training Kit includes presentations, hands-on labs, demos, and event materials. This content is designed to help you learn how to utilize the .NET 3.5 Enhancement features including: ASP.NET MVC, ASP.NET Dynamic Data, ASP.NET AJAX History, ASP.NET Routing, ADO.NET Data Services, ADO.NET Entity Framework, WCF 3.5 SP1, and the .NET Framework Client Profile.
You can find it at http://www.microsoft.com/downloads/details.aspx?FamilyID=355c80e9-fde0-4812-98b5-8a03f5874e96&displaylang=en
Ken Zheng
Posted in .Net | Tagged: .Net 3.5 | Leave a Comment »
Posted by ken zheng on August 26, 2008
After installed SP1 for visual studio 2008. I started playing the ADO .NET Entity. To create a entity class is very simple.
1. Add New Item
2. Select ADO .NET Entity Data Model
3. I called NorthwindEF, then follow the wizard. In this example, I only add Product and Category Tables from Nothwind database
Visual Studio will generate a NorthWindEF.edmx and code behind file
A simple example is
using (NorthwindEFEntities context = new NorthwindEFEntities())
{
var query = from p in context.Products where p.ProductName.Contains("b") && p.Discontinued == false select p;
Console.WriteLine("result 1");
foreach (var p in query)
{
p.CategoriesReference.Load();
Console.WriteLine(" {0}",p.Categories.CategoryName);
}
var categories = from c in context.Categories
select c;
Console.WriteLine();
Console.WriteLine("result 2");
foreach (Categories c in categories)
Console.WriteLine(" {0}", c.CategoryName);
var query2 =
(from p in context.Products select p).ToList();
//Add Product
Console.WriteLine("Add a product");
Products _product = new Products();
_product.ProductName = "Pizza";
_product.Categories = categories.First();
_product.Discontinued = false;
context.AddObject("Products", _product);
context.SaveChanges();
Console.WriteLine("New ID {0}", _product.ProductID);
//Update Product
_product.SupplierID = 1;
context.SaveChanges();
//Delete Product
var del_prod = query2.LastOrDefault();
context.DeleteObject( del_prod);
context.SaveChanges();
Console.WriteLine("Completed!");
}
Be careful with p.CategoriesReference.Load(). If you don’t call this method. The Category object will be null
Posted in .Net, VS2008 | Tagged: ADO .NET Entity | Leave a Comment »
Posted by ken zheng on August 26, 2008
Today, I learned some useful javascript way. Thanks for Damian for his IPhone Speed http://iphonespeedcheck.com
First you can write your script like below to use variable
var $ = function(selector) {
return document.querySelector(selector);
}
var $debug = function(msg)
{
if(window.console) {
window.console.log(msg);
}
else {
alert(msg);
}
}
var $dispatch = function(code, delay) {
return window.setTimeout(code, delay);
}
var $repeat = function(code, delay) {
return window.setInterval(code, delay);
}
var $cancel = function(id) {
window.clearInterval(id);
window.clearTimeout(id);
}
var $create = function(tag) {
return document.createElement(tag);
}
var $createText = function(text) {
return document.createTextNode(text);
}
so you can call the function by
$debug(“Running latency test…”);
you can use jquery to get element using particular css id
$(“#blackOut”).style.left = 0;
Posted in JavaScript | Tagged: JavaScipt | Leave a Comment »
Posted by ken zheng on August 19, 2008
• CTRL+SHIFT+ESC (Open Task Manager)
• Windows Logo+E (Open My Computer)
• CTRL+ESC (Display the Start menu)
• Windows Logo+D (Display the desktop)
• Windows Logo+R (Open the Run dialog box)
• CTRL+TAB (Move forward through the tabs)
• ALT+TAB (Switch between the open items)
Posted in Uncategorized | Leave a Comment »
Posted by ken zheng on August 13, 2008
I had one problem that need to be addressed is when Button1 clicked to call Button2 postback.
You can achieve it by writing a Javascript function
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
function doingThings()
{
// post back to raise the button's click event
<%= ClientScript.GetPostBackEventReference(Button2, string.Empty) %>
<asp:Button ID="Button1" runat="server" Text="Button1" OnClientClick="doingThings();return false"/>
<asp:Button ID="Button2" runat="server" Text="Button2" />
}
//-->
</SCRIPT>
This code will cancel the Button1 Click event and the postback is caused by Button2
And below function will return the Button which raised postback. You will see it is Button2
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Label4.Text = DirectCast(GetPostBackControl(Me.Page), Button).ID
End If
End Sub
Public Shared Function GetPostBackControl(ByVal page As System.Web.UI.Page) As System.Web.UI.Control
Dim control As Control = Nothing
Dim ctrlname As String = page.Request.Params("__EVENTTARGET")
If ctrlname IsNot Nothing AndAlso ctrlname <> [String].Empty Then
control = page.FindControl(ctrlname)
Else
' if __EVENTTARGET is null, the control is a button type and we need to
' iterate over the form collection to find it
Dim ctrlStr As String = [String].Empty
Dim c As Control = Nothing
For Each ctl As String In page.Request.Form
If ctl Is Nothing Then Continue For
' handle ImageButton controls ...
If ctl.EndsWith(".x") OrElse ctl.EndsWith(".y") Then
ctrlStr = ctl.Substring(0, ctl.Length - 2)
c = page.FindControl(ctrlStr)
Else
c = page.FindControl(ctl)
End If
If TypeOf c Is System.Web.UI.WebControls.Button OrElse TypeOf c Is System.Web.UI.WebControls.ImageButton Then
control = c
Exit For
End If
Next
End If
Return control
End Function
Posted in .Net | Leave a Comment »
Posted by ken zheng on August 13, 2008
Posted in .Net | Tagged: WCF | Leave a Comment »
Posted by ken zheng on August 13, 2008
Posted in .Net | Tagged: Asychronized Callback | Leave a Comment »
Posted by ken zheng on August 12, 2008
Posted in Uncategorized | Tagged: TechEd | Leave a Comment »
Posted by ken zheng on August 7, 2008
command1.ExecuteNonQuery(File.OpenText(“C:\Test.sql”).ReadToEnd());
Posted in Uncategorized | Leave a Comment »
Posted by ken zheng on August 7, 2008
I use “SetAttribute\(.*\Date\*.ToString” or SetAttribute\(.*\Date.ToString, and check Use Regular Expression in Find box
Posted in Handy Tips | Leave a Comment »