Category Archives: C#

Merge Rows in GridView – One Column or Multiple Columns

I few days earlier my client asked me if it is possible to merge rows with same repetitive data so that the reports become more readable. Please refer to the screen shots below to get a better picture of their … Continue reading

Posted in ASP.NET, C#, Knowledge Sharing | Leave a comment

Creating tamper proof Url in asp.net – a way to prevent spoofing and forged HTTP requests

Consider the following URL- http://www.mysite.com/orders.aspx?id=10 Now the problem is that anybody having this link can view more data than authorised and required by simply changing the value of id to say 16,17,18,19… Another problem could be that script tags could … Continue reading

Posted in ASP.NET, C#, Knowledge Sharing, Troubleshooting | Leave a comment

How to load a server side image in Silverlight Image control – another way to reduce XAP size

Direct references to images should be avoided in a Silverlight project as it makes the XAP file heavier. An alternative could be to have the images on server and load images by creating bitmap of the image by using the … Continue reading

Posted in ASP.NET, C#, Knowledge Sharing, Silverlight, Troubleshooting | Leave a comment

Why Interfaces in C#

Consider the following code snippets- // Code for the IAccount interface module. public interface IAccount { void PostInterest(); void DeductFees(IFeeSchedule feeSchedule); } class BusinessAccount : IAccount { void IAccount.PostInterest() { // Code to post interest using the most favorable rate. … Continue reading

Posted in C#, Knowledge Sharing, Troubleshooting | 4 Comments

Interface with Multiple Base Interfaces

As you build interface hierarchies, in C# it is permissible to create an interface that derives multiple base interfaces. Example- public interface ICar { void Drive(); } public interface IUnderWaterCar { void Drive(); } //implementing an interface with two interfaces … Continue reading

Posted in C#, Knowledge Sharing, Troubleshooting | 5 Comments

Silverlight – C# – How to set a XAML element’s style from code behind

XAMLelementName.Style = Application.Current.Resources["Style"] as Style; // If your style is defined in App.xaml Application.Resources section XAMLelementName.Style = this.Resources[StyleKey] as Style; // if your style is defined in Page.XAML UserControl.Resources section XAMLelementName.Style = button.Resources[StyleKey] as Style; // if your style is … Continue reading

Posted in C#, Knowledge Sharing, Silverlight, Troubleshooting | 2 Comments

Silverlight – C# – How to set XAML element’s margin from code behind

XAMLelementName.Margin = new Thickness(1, 2, 3, 4); // OR, if you need uniform thickness XAMLelementName.Margin = new Thickness(5);

Posted in C#, Knowledge Sharing, Silverlight, Troubleshooting | 3 Comments

Download a file from server or open a web address in a pop-up window from Silverlight client

You can use HyperlinkButton control to do this. Example- <HyperlinkButton Name=”hplTemplete” Content=”Open Google in New Window” NavigateUri=”http://www.google.com” TargetName=”_blank” /> In case you need to set its NavigateUri from code behind, use following code- hplTemplete.NavigateUri =new Uri(“http://www.google.com”);

Posted in C#, Knowledge Sharing, Silverlight | 4 Comments

File Upload from Silverlight Client – A Generic http Handler to Upload File

From Silverlight client, you can upload files on server. For this you need a httphandler. Following is the code for the httphandler- using System; using System.Web; using System.IO; using System.Configuration; namespace WebProject.Web { public class FileUpload : IHttpHandler { public … Continue reading

Posted in C#, Knowledge Sharing, Silverlight | Leave a comment

What is the benefits of using C# Properties over Fields

Many benefits- 1. Properties are used for data binding; Fields aren’t. 2. Encapsulation can be achieved with Properties, not with Fields. An example below- public int Order { get { return m_order; } set { //Encapsulation goes here // Put … Continue reading

Posted in C# | 3 Comments