Sunday, September 14, 2008
Sending data from javascript to a .Net object
__doPostBack("FirstName","Tom");
performs a postback, sending the variable "FirstName" with the value "Tom".
In your code (C# in my case) you can read in this variable and use it as you will
Page.ClientScript.GetPostBackEventReference(this,"arg");
if (Page.IsPostBack)
{
string eventTarget = Page.Request["__EVENTTARGET"];
string eventArgument = Page.Request["__EVENTARGUMENT"];
if (eventTarget != String.Empty && eventTarget == "FirstName")
{ //do what you will with the eventArgument }
}
Note that you would replace "FirstName" in the second if statement with the name of your variable you used in the "__doPostBack" statement.
Wednesday, September 10, 2008
Value type and reference type
value type and reference type
A data type is a value type if it holds the data within its own memory allocation. A reference type contains a pointer to another memory location that holds the data.
Value Types
Value types include the following:
· All numeric data types
· Boolean, Char, and Date
· All structures, even if their members are reference types
· Enumerations, since their underlying type is always SByte, Short, Integer, Long, Byte, UShort, UInteger, or ULong
Reference Types
Reference types include the following:
· String
· All arrays, even if their elements are value types
· Class types, such as Form
· Delegates
Elements That Are Not Types
The following programming elements do not qualify as types, because you cannot specify any of them as a data type for a declared element:
· Namespaces
· Modules
· Events
· Properties and procedures
· Variables, constants, and fields
Tuesday, September 9, 2008
What is covariance and contravariance. Did Delegate and method overriding support these.
What is covariance and contravariance. Did Delegate and method overriding support these.
Covariance and contravariance provide a degree of flexibility when matching method signatures with delegate types. Covariance permits a method to have a more derived return type than what is defined in the delegate. Contravariance permits a method with parameter types that are less derived than in the delegate type.
Covariance
class Mammals
{
}
class Dogs : Mammals
{
}
class Program
{
// Define the delegate.
public delegate Mammals HandlerMethod();
public static Mammals FirstHandler()
{
return null;
}
public static Dogs SecondHandler(){
return null;
}
static void Main()
{
HandlerMethod handler1 = FirstHandler;
// Covariance allows this delegate.
HandlerMethod handler2 = SecondHandler;
}
}
ContravarianceSystem.DateTime lastActivity;
public Form1()
{
InitializeComponent();
lastActivity = new System.DateTime();
this.textBox1.KeyDown += this.MultiHandler;
//works with KeyEvent Args
this.button1.MouseClick += this.MultiHandler;
//works with MouseEventArgs
}
// Event hander for any event with an EventArgs or// derived class in the second parameter
private void MultiHandler(object sender, System.EventArgs e)
{
lastActivity = System.DateTime.Now;
}
http://msdn.microsoft.com/en-us/library/ms173174(VS.80).aspx
Friday, September 5, 2008
Different properties provided by Object-oriented systems
1. Read-only Property
2. Write-Only Property
3. Read Write Property
4. Static Properties
4. Auto-implemented properties
If you define a property with only a get accessor, that property will be read-only. Likewise, if you define a property with only a set accessor, you’ll end up with a write-only property. And lastly, a property with both accessors is a read-write property
Read-Write Property
public string CarModel
{
get { return model; }
set { model = value;}
}
Read Only
public string CarModel
{
get { return CarModel; }
}
Write Only
public string CarModel
{
set { model = value;}
}
Auto-implemented properties is the C# 3.0 new feature that make property-declaration more concise. It helps you to save some of your time for typing a lot of codes. Please take a look the following code to know how it looks like.
class Car
{
public string Speed
{
get; set;
}
}
Wednesday, September 3, 2008
differences strored procedures and triggers
Trigger:It is a fragment of code that tells Database to fire or run BEFORE or AFTER a table is modified. It has the power to make sure that a column is filled in with default information make sure that an audit row is inserted into another table after finding that the new information is inconsistent with other stuff in the database.