Sunday, November 2, 2008

LINQ - C# Programming

Get DataSource
In C# as in most programming languages a variable must be declared before it can be used. In a LINQ query, the from clause comes first in order to introduce the data source (customers) and the range variable (cust).

//QEmp is an IEnumerable
var QEmp = from e in Emp
select e;

Filter

Probably the most common query operation is to apply a filter in the form of a Boolean expression. The filter causes the query to return only those elements for which the expression is true. The result is produced by using the where clause. The filter in effect specifies which elements to exclude from the source sequence.

var QEmp = from e in Emp
where e.Country == "India"
select e

----AND Condition----
where e.Country == "India" && e.Name == "Ashvin"

----OR Condition----
where e.Country == "India" || e.Name == "Ashvin"

Ordering
The orderby clause will cause the elements in the returned sequence to be sorted according to the default comparer for the type being sorted. For example, the following query can be extended to sort the results based on the Name property. Because Name is a string, the default comparer performs an alphabetical sort from A to Z.
var QEmp = from e in Emp
where e.Country == "India"
orderby e.Name ascending
select e


Read More...

GridView Control

In MySQL, you would need to supply the LIMIT keyword in order to get a specific set of rows. With GridView’s paging feature enabled, everything is done for you. Neat huh. Took me like a day in getting this one to work though because I had problems with the update and delete function. Since I am using MySQL, turns out when you do parameters in your query commands, the @ sign does not work because it is only for MS SQL. You would have to change the @ to ?.

Read More..

Introducing the "DotNetNuke" Web Application Framework

Web Application Framework is a robust software library used as the basis for building advanced Web applications. A Web Application Framework typically contains a well-defined architecture and an abstract set of reusable components that are specifically designed to simplify development, enforce consistency, increase productivity, and improve application quality. Typical features include modular architecture, membership management, security and role management, site organization and navigation, error and event logging, data access and caching, search and syndication, and extensibility at every level. Frameworks are used in corporations, public sector, private sector, small businesses, nonprofit organizations, and even individual Web sites.

Although the concept has always been relevant, Web Application Frameworks have just come back into favor in recent years. This is likely a result of the ever-pervasive basic business philosophy emphasizing a reduction in the Total Cost of Ownership and increase in the Return On Investment. Web Application Frameworks can provide big wins in both of these categories because they allow developers to focus on the high-level business processes while leveraging a rock-solid application foundation.

DotNetNuke is a Web Application Framework that provides a highly extensible development environment, based on published standards and proven design patterns. Since Web Application Frameworks are generic by nature, they can be used as the underpinnings for any number of powerful Web applications. From Community Portals to high volume E-Commerce shopping malls, from Content Management Systems (CMS) to Customer Relationship Management Systems (CRM), the DotNetNuke Web Application Framework provides the fundamental services to build highly functional and scalable Web applications. To back up this claim, the DotNetNuke Web Application Framework is distributed as part of a fully functional CMS - the DotNetNuke Enterprise Portal.

Introducing DotNetNuke
Necessity is the mother of invention. In classic open source fashion, I originally created the application because I was interested in a way to provide functional Web sites to amateur sports organizations and could not find a suitable proprietary alternative. After investing significant effort only to discover that my business goals were not going to be realized, I decided to release the application as an open source community project. Version 1.0 of DotNetNuke was released December 24, 2002 (Christmas Eve). Since then, DotNetNuke has evolved at an exponential rate, recently surpassing 200,000 registered users, 800,000 downloads, and maintaining a consistent weekly project activity rank of #15 on SourceForge.Net.

Read More..

Saturday, November 1, 2008

Using URL Rewriting With Web Parts

Web parts are a great new system for allowing personalization of web sites by end users that was introduced in ASP.NET 2.0. However, it isn't useful when used in combination with URL rewriting.

URL rewriting allows you to respond to requests from dynamic URLs by redirecting the handling to a different .ASPX file on your server. This can be used to make your URLs more readable and improve your search engine optimization (SEO), instead of using long query parameters.

Some example systems for implementing this are UrlRewriter.net and UrlRewriting.net.

When you use web parts in combination with a rewritten URL, the web parts will all be shared by all of the URLs that are rewritten to the same .ASPX file. This library corrects this by replacing the WebPartManager with RewritableWebPartManager and the SqlPersonalizationProvider with RewritableSqlPersonalizationProvider.

It also provides additional functionality in the form a personalization levels. This allows you to share common personalization settings amonst multiple URLs. When a user is browsing, if no personalization is specified at a particular level, the personalization defined at a higher level is displayed instead. For example, in a web store scenario you can allow the store operators to provide shared personalization that all users will see. Using levels, they can set personalization
that will appear on all item pages, such as a disclaimer, and then override that personalization with a different disclaimer on a specific item's page.

Read More..

Handy ASP.NET Email Control

Most websites have the need for some sort of "feedback form" or "email-us" page, which, as we know, is tedious to re-develop on every site, even in .NET. I have developed this simple E-Mail control in VB.NET that can be wrapped around any form to be turned into an email form, even with file inputs.

The first major thing to overcome is the property which must be set just above the CLASS in the .ascx.vb file (no extra linebreaks). This allows the User Control to access the controls on the .aspx page where it is used.

_ 'No extra linebreak after this!!
Public MustInherit Class MailAnything
Inherits System.Web.UI.UserControl

If you do have a file input on your web form remember to set the enctype="multipart/form-data".

Another important thing to remember is to use Web Forms Labels to name your fields on the web form so that it can be read by your user control and form part of the email.

Read more..

How to Convert Your Site To A MasterPage Site in 3 Steps

Once you have your design converted into HTML/CSS, why should you have to worry about breaking it every time you create a new page? Abstract yourself from this with MasterPages, while still enabling yourself to easily make design changes. MasterPages are wonderful for standardizing your site and your design, in addition to making it easier to maintain and to build new pages. They are a very powerful and easily customizable way to template your site. This article is for those who don’t have much or any experience with MasterPages or are converting an old ASP.NET site to a MasterPage-driven site. If this is you, don’t be afraid—You can do it in just three easy steps!
1. Create a new MasterPage

Right click your project, go to “Add” and then “New Item…” and select MasterPage. Name it something useful, like “main.master” and hit ok. You should be presented with a barebones XHTML skeleton. Notice that your skeleton has this tag in it: . This is the location where your content will be loaded from your .aspx pages. Fill your new MasterPage with the XHTML that you wish to use on every page. If you want some things to change based on certain variables, you can do so in the codebehind. Treat the MasterPage like any other .aspx page. The only thing different about it (on a basic level) is that it does not contain your content, but rather what encompasses your content.
2. Link your old pages to your MasterPage in the Page Directive

In your <%@ Page directive, add the following attribute: MasterPageFile="~/YourMasterPage.Master"
3. Tell the MasterPage What Content Goes Where

If you only have one ContentPlaceHolder, you will add the following tag around all of your content in your .aspx pages: Hello, World!, where “ContentPlaceHolder1″ is the ID of the placeholder in your MasterPage that you linked to in step 2. If you have more than one ContentPlaceHolder in your MasterPage, simply wrap the tags around the correlating content.

And that’s it! That’s really all there is to it! Just apply steps 2 and 3 to each of your .aspx pages. There is an optional step for those who may have changed their pages’ codebehind inheritance:

Read More..

ASP.NET: How to Integrate Both Google Checkout and PayPal In 3 Steps

Trying to get Google Checkout and PayPal to work with a custom .NET site or solution has been a problem for as long as they’ve been around. If you don’t know what you’re doing, it can be a daunting task, and sometimes even if you do know what you’re doing! Well, I am going to take the guesswork out of this chore once and for all, as I have recently discovered the ultimate way to integrate these payment gateways into your website.

The Solution
In their documentation, PayPal and Google Checkout both mention that you must put their code into your site exactly as they have it, using the HTML forms they way they have structured them. This is not true. There are only a few bits of information that are required, and so long as they are present in an acceptable fashion, your pass-off to these gateways will work smoothly and flawlessly.

1. Get rid of your form tags.

2. Create image buttons for Google Checkout and PayPal

3. Create your hidden inputs to transfer information to PayPal and Google Checkout

4. BONUS: Hook up Google Analytics.


Read More..