Saturday, 27 June 2009

HTML Encoder Decoder

A simple one.

How to Know Which Control Was Clicked?

In aspx.cs:


protected override void OnInit(EventArgs e)
{
base.OnInit(e);
string CtrlID = GetClickedControlID();
ClientScript.RegisterStartupScript(this.GetType()
, "sourceofpostback", "<script type='text/javascript'>window.onload=new function(){alert('Control ID " + CtrlID + " caused postback.');}</script>");

}
private string GetClickedControlID()
{
string CtrlID;
if (String.IsNullOrEmpty(Request.Form["__EVENTTARGET"]))
{
if (String.IsNullOrEmpty(Request.Form[hidSourceID.UniqueID])) return null;
CtrlID = Request.Form[hidSourceID.UniqueID];
}
else
{
CtrlID = Request.Form["__EVENTTARGET"];
}
return CtrlID;
}

In .aspx:
<head runat="server">
<script type = "text/javascript">
function SetSource(SourceID)
{ document.getElementById("<%=hidSourceID.ClientID%>").value = SourceID; } </script>

</head>
<body>
<form id="form1" runat="server">
<asp:HiddenField ID="hidSourceID" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick = "SetSource(this.id)" />
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack = "true" />

Friday, 26 June 2009

Different Ways of Selecting a Control in ASP.NET using JavaScript

Accessing an HTML control:

var myHtmlControl = document.getElementById('htmlTextBox');
var myHtmlControl = $('#htmlTextBox');

Accessing an ASP.NET Server control:

var myServerControl = document.getElementById('serverTextBox');
var myServerControl = document.getElementById("< % = serverTextBox.ClientID % > ");
var myServerControl = $('# < % = serverTextBox.ClientID % > '); // JQuery
var myServerControl = < % = serverTextBox.ClientID % >;
var myServerControl = eval("serverTextBox.ClientID");
var myServerControl = $get("serverTextBox.ClientID"); // ASP.NET AJAX Library
...

Tuesday, 16 June 2009

WCF - Questions to be answered when implementing

What are the questions that you need to answer and consider when creating a WCF service?

ServiceContract
  • What service contracts do I need?
  • What SessionMode (Allowed/NotAllowed/Requied) do I need to support for my service contract?
  • What ProtectionLevel my service contract needs (None/Sign/EncryptAndSign)?
  • Do I need to support CallbackContract?

ServiceBehaviour

  • Which ServiceContract my ServiceBehaviour needs to implement?
  • Which AddressFilterMode do I need for my ServiceBehavoir (Any/Exact/Prefix)?
  • Which ConcurrencyMode do I need for my ServiceBehavior (Multiple/Reentrant/Single)?
  • Which InstanceContextMode do I need for my ServiceBehavior (PerCall, PerSession, Single)?

EndPoint and Binding

  • What are the endpoints I want to expose? How many? (which address, binding, contract)
  • What are the bindings I want to have? e.g. basicHttpBinding, wsHttpBinding
  • What security mode my binding should have? e.g. None/Message/Transport level security

...

Saturday, 6 June 2009

Microsoft Web Platform Installer



The Microsoft Web Platform Installer (Web PI) is a free tool that makes it simple to download, install and keep up-to-date with the latest components of the Microsoft Web Platform, including Internet Information Services (IIS), SQL Server Express, .NET Framework and Visual Web Developer.

Monday, 1 June 2009

TFS

Integration with Windows Explorer
Automated Build
  • http://msdn.microsoft.com/en-us/library/ms181286.aspx
Team Explorer
  • It enables team members to access to the TFS from a web url rather than Visual Studio

How to Reduce Complexity in Software

Problem:
Complexity is number one enemy in developing a maintainable and extendable system and it's the main concern of architects.

The more complex a system is, the more costly it will be to be maintained or extended.

Solution1:
One of the ways to reduce complexity is to seperate the concerns or partitioning the concerns. You may want to partition your source code into different layers. For instance, typically you partition your application to have database, data access, business logic and UI  layers.

In WCF for example, you partition your service layer to service contracts, message contracts, data contracts, service implementation and transformation layers.

Solution2:
Another way to reduce complexity is to use refactoring techniques such as making methods to do simple and structured activities.

Solution3:
Another approach is to lower the coupling and dependencies between your classes for instance developing to an interface rather than an implementation (concrete class).