Moses on DotNetSlackers

.Net Gorean Lifestyler

This site

News

@ Cambridge, UK

Blogs

Sponsors

  • MaximumASP
  • Packet Sniffer
    Custom Essay
  • fax by email
Custom paging with LINQ to SQL.

Here is 4 posts that discuess custom paging using LINQ to SQL. Post include demo and explination with source code download.


Hope you'll enjoy them.

 

Posted: Jul 23 2008, 03:31 PM by mosessaur
Filed under:
jQuery.UI Messenger\Outlook like message notification Widget

Few days I read Matt's post about building jQuery.UI ProgressBar widget. On that same day I followed his post and build one simple widget, Messenger\Outlook like message notification Widget.

Check it out and I hope you'll like it. Demo and Download is included in the main post.

MosesOfEgypt.NET, My new domain and blog
In the last 2 days I was successfully moved my blog. My new blog is http://www.mosesofegypt.net. I installed BlogEngine 1.3 and started to migrate few of my old posts. Successfully did that. And officially started my own blog on my own domain. My host is http://www.otechnology.net based on Australia. Actually they provided me with great host facility. Hope you'll like it the new blog, and soon new posts to come up on it.
Posted: Feb 17 2008, 07:00 PM by mosessaur
Filed under: ,
ASP.NET AJAX ComboBox

Back to April 2007 I posted about building an ASP.NET AJAX ComboBox. It was an attempt to rewrite a ComboBox Control I made to fulfil certain issues I faced with 3rd Party Controls. One of those issue was performance as most of 3rd Party control are rendering heavy HTML because of extinsive features they put on their controls which I do not need. So This post is supposed to be an extensions to my old post as well as my article about building Simple ASP.NET ComboBox.

Attached to this post is the ASP.NET AJAX ComboBox. The archive is also containing 3 other very simple controls. The controls are developed using ASP.NET AJAX 1.0. Client Side Controls are written using Script#. I've posted earlier about Script# and my experience with it, so feel free to have a look at that post.

Now back to ASP.NET AJAX ComboBox. The control is very simple, you can consider it as composite control of simple ListBox and TextBox, however it doesn't inherit from CompositeControl. It directly inherit from ListControl to support binding out of the box and many other features that do need any to be rewritten.

How to use this simple control? The control has a property called EditingStyle. The property accepts one of the following values:

  • DropDownList: Pretty similar to normal DropDownList behavior.
  • ComboBox: TextBox is enabled for free text editing. No auto complete is offered.
  • DropDownCombo: TextBox is enabled for free text editing, Auto complete is offered for the available list items.

For the look and feel of the control there are few CSS style properties described bellow:

  • CssClass: Normal CSS class for the TextBox.
  • HoverCssClass: Hover CSS class for the TextBox when mouse goes over it.
  • FocusCssClass:Focus CSS class for the TextBox when recieving input focus.
  • ReadOnlyCssClass: ReadOnly CSS class, used when the control is in read only state. Note that ReadOnly is different from Enabled property.

I did not expose any client side method to public, actually because there are no needed client side methods so far. But there are few properties are exposed as public, I did that for development time use, but never face a case that I needed to use them from client code. These properites represents the DOM Elements of:

  • Text box -> get_textBox()
  • Drop down image -> get_dropDownImage()
  • List control -> get_listBox()

Also there are some useful properties exposed that represents selected item Index,value and text:

  • get_selectedIndex() returns integer
  • set_selectedIndex(ndx) accepts integer parameter
  • get_value() returns selected item value
  • get_text() returns text of the TextBox

The control expose only one event to develpers. This event is change event of the List Box. The client function name used to handle this event should be set to OnClientChange property of the control. This function should have the following signature

function onClientChange(s,e) {.....}

s parameter is the sender onject, it always hold a reference to the control itself.
e parameter is an EventArgs argument, it is always empty not used in other words currenlty.

So if you wish to access curently selected index of the comboBox you could something similar to this:

function ProductChanged(s,e){
alert(s.get_selectedIndex());
}

Now the following is code sample of how to declare the ComboBox.

<cc1:combobox id="ComboBox1"
EditingStyle="DropDownList"
CssClass="textbox"
HoverCssClass="textboxhover" ReadOnlyCssClass="textboxreadonly"
FocusCssClass="textboxfocus"
OnClientChange="ProductChanged"
datasourceid="SqlDataSource1" datatextfield="ProductName" datavaluefield="ProductId" runat="server" />

.....

<script type="text/javascript">
            function ProductChanged(s,e)
            {
                alert(s.get_selectedIndex());
            }
</script>

There is an issue with this control, that it is missing good design time support so sorry for this, sorry for this!

I think this is all I have in mind now, if I found something important to be mentioned I'm gonna posted as soon as I can. Thanks for all those who supported me by suggestions and testing in my previous version. And sorry if the old one wasn't that much satisfying! hopefully this one would be better.

UPDATE:

  1. BUG 01 09 Jan 2008:When placing the control inside a container (DIV, Fieldset etc....) and set positioning to this container, the List Box is not displayed in its approperiate location.
  2. BUG 01 FIX 12 Jan 2008: Fixed normally on Opera and IE. FireFox is also fixed with workaround that I cannot guarantee 100% that it is totally fixed. For some reason FF do not calculate position the way IE and Opera do:
    Here is how IE and Opera fix work:
    var textBoxBounds = Sys.UI.DomElement.getBounds(this._textBox);
    var offsetParent = Sys.UI.DomElement.getLocation(this._textBox.offsetParent);
    var x = textBoxBounds.x - (offsetParent.x + 2); //Added extar 2 pix to make the list display exactly underneath the textBox
    var y = (textBoxBounds.y + textBoxBounds.height) - (offsetParent.y + 1); //Same thing as above
    Sys.UI.DomElement.setLocation(this._listBoxContainer, x, y);
    The above code work perfectly in both IE and Opera but not in FF for some reasons I don't know! So I had to write similar code but I had to increase those extra pixels extra ordinary like this
    var x = textBoxBounds.x - (offsetParent.x + 12); //Added extar 2 pix to make the list display exactly underneath the textBox
    var y = (textBoxBounds.y + textBoxBounds.height) - (offsetParent.y + 27); //Same thing as above
    I've tested it and it is working properly, but my test was very fast. Hopfully this bug is fixed. Download attached Project as it contains the fix. You can test this bug fix on ~\Working\WebForm1.aspx
  3. Bug 02, fixing Bug 01 caused a bug when placing ComboBox within GridView. The list is not positioned correctly under the TextBox, and actually it flies away.
  4. Bug 02, FIX . 6th Feb 2008.

 

kick it on DotNetKicks.com
Download: The Visual Studio 2008 and .NET Framework 3.5 Training Kit

Few weeks ago Microsoft released a useful training kit for Visual Studio 2008 and .NET Framework 3.5 containing Labs, Demos and PPTs. The Visual Studio 2008 and .NET Framework 3.5 Training Kit includes presentations, hands-on labs, and demos.

This content is designed to help you learn how to utilize the Visual Studio 2008 features and a variety of framework technologies including: LINQ, C# 3.0, Visual Basic 9, WCF, WF, WPF, ASP.NET AJAX, VSTO, CardSpace, SilverLight, Mobile and Application Lifecycle Management. Before you start downloading, I recommend that you read the System Requirement section if you are using Windows XP. Windows XP is not listed!!

Click here for the download page.

SQL Server 2005, Clean your Database Records & reset Identity Columns, all in 6 lines!

Well, I had a small issue regarding writing a script to clean a database we have and reset its identity columns in all tables. Although the database wasn't huge one (less than 100 tables) I had to trace relations to be able to delete child table's records before parent's ones because of the foreign key constraints. The solution is disable the foreign keys and delete records with no fear of any errors then enables the constraints again.
Well, I found a solution to disable all constraints without the need to go on each table and disable it manually. and I was happy to know that I can use this solution in deleting all records from all tables. Not only this I was able to use the same solution to reset identity columns in all tables.
The solution was to use this built in stored procedure sp_MSforeachtable. For help about this proc search for it in Books online or use this sp_helptext sp_MSForeachtable.
Now back to my 6 lines, bellow is how I re-zeroed my Database:

/*Disable Constraints & Triggers*/
exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'

/*Perform delete operation on all table for cleanup*/
exec sp_MSforeachtable 'DELETE ?'

/*Enable Constraints & Triggers again*/
exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'

/*Reset Identity on tables with identity column*/
exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(''?''), ''TableHasIdentity'') = 1 BEGIN DBCC CHECKIDENT (''?'',RESEED,0) END'
kick it on DotNetKicks.com
MSDN Magazine Cutting Edge: ASP.NET AJAX
Dino Esposito wrote a serious about ASP.NET AJAX on MSDN Magazine Cutting Edge section. I would like to share these good links with you so here they are: Happy AJAXfying
Tip: Generating Local Resource Files

As I was working on multingual User Interface project; it was needed to generate resource files for all aspx & ascx files.
I knew that VS.NET 2005 has a local resource file generator. But it was weird when I select my ASPX page or user control and go to Tool menu and find that there are no Generate Local Resources command on the menu!

It didn't take so much time, I found the solution on ASP.NET Forums. It was simple: "he menu 'Tools > Generate Local Resources' is available when you display an aspx page or ascx". Also you must switch to design veiw before you Generate your local resources.

 

Using Script# to build ASP.NET AJAX Enabled Controls

Recently I’ve finished reading the marvelous book ASP.NET AJAX IN ACTION. After that I thought to start build some simple ASP.NET AJAX Enabled Controls. Unfortunately I’m not an advanced JavaScript developer and I consider most of the scripts I wrote a simple bad coding practice scripts. So ASP.NET AJAX Scripting framework would enhance my Scripting style! But again I’m not an advance JavaScript developer. I know JavaScript basics that would let me go ahead and would give a crash start. And I’ve tried a tool made by Nikhil Kothari named Script#. A tool that lets me writes JavaScript for ASP.NET AJAX Enabled Controls using C#, a language that I’m used to develop with.

Script# in few words is C# compiler that converts C# code to JavaScript Code.

So I started to use Script# and I was amazed by how fast I can accomplish developing my simple controls using this tool. In this post I’m going to show my experience with this tool and focus on things I wished to have in it but so far it doesn’t support.

Simply when I started with Script#; I wanted to build a simple styled TextBox control that have style when hover over it or receive a focus or even when the TextBox is in read-only state. Very simple control isn’t it?!

Well, Script# provides you with base classes to inherit from if you wish to build AJAX Enabled Controls. These classes are Sys.UI.Control and Sys.UI.Behavior. As you might notice, these classes are mapping to the Client Classes with the same name. When you compile your project you’ll get a JavaScript output file with your client classes you defined in the C#. Of course your client class generates will inherit from the client class you defined in your C# code. It is important to note that we are talking here about client classes not the ASP.NET Server Control classes.

The code for my classes is attached to the post, all you need is to download the Script#, install it and compile the Projects attached. Then examine the JavaScript files generated. Also you’ll notice that there is 2 JavaScript files are generated “YourProjectName.js” and “YourProjectName.debug.js”. The first one is the release version which is compressed and hard to read. The other one is the debug version, not compressed and has all your debug details on it. That means inside your C# code you may call Debug.Trace() method, this method class will not be available in the release version of the script but of course it will be generated in the debug version.

At the time I’m writing this post I was using Script# v0.4.2.0. So far my comments about this wonderful tool are only 2:

·         When calling DomEvent.AddHandlers method it generate in JavaScript the fully qualified client method “Sys.UI.DomEvent.addHandlers” although there is a simple shortcut for it which is $addHanlders. Same thing for DomEvent.AddHandler method which has equivalent shortcut $addHandler.

·         Second comment is that I face the need to use readOnly property of TextBox. TextBox will render even an input element with type=”text” or textarea element. Both have readOnly property that can be accessed through client code. Script# provides nearly full DOM support in managed classes that is compiled and generates JavaScript code as output. So in Script# input element with type = “text” and textarea are represented as System.DHTML.TextElement and System.DHTML.TextAreaElement respectively. The issue here is both classes do not expose ReadOnly property!!
This issue made me access readOnly property through this code DOMAttribute att = this.Element.GetAttributeNode("readOnly");. Again facing another issue which is browser compatibility. IE returns readOnly property as Boolean true/false. FireFox and Opera return readOnly property as string; empty or null if the element is not read-only and “readonly” value if the element is read-only. A funny note, Opera returns “readOnly” with capital O if the element is read-only.

There are some other comments, but not sure how far Script# can reach to enable such facilities. For example, as mentioned above I had to access readOnly property using a long line of code. This code is generated like this var att = this.get_element().getAttributeNode('readOnly'); a long line comparing to this code this.get_element().readOnly; especially if you can save few extra lines by accessing the property directly.

Finally, Script# is really powerful tool that saves time and learning curve of JavaScript. You need to have C# programming skills and a good vision of DOM so you can gain maximum benefits of the Script#.
ASP.NET AJAX In Action Book

Currently I'm enjoying reading ASP.NET AJAX In Action Book written by Alessandro Gallo, David Barkol, and Rama Krishna Vavilala. As the time I'm writing this post, I've finished Part 1 and comming across Chapter 8. So far I found the book very informative with rich examples and samples in a tutorial like fashion. Beside I enjoy the writers way of delivering the information so the book is not boring.

This is my first Book to read about ASP.NET AJAX so I cannot tell this is the best book in the market. But I've a glance look at some other books published earlier and I found that ASP.NET AJAX In Action is one of the best and maybe would be at the top of those best books.

The book is 100% fits ASP.NET AJAX newbies -Like me!- as well as those advanced developers and I think it would fit to be used as a reference later.

The book digs deep into ASP.NET AJAX and show how things are managed under the hood with easy and simple way. For example the books explains how the UpdatePanel works and how it is interacting with ScriptManager and PageRequestManager showing the different client events related to PageRequestManager client Class.

The book covers every aspect of ASP.NET AJAX Library showing also its limitations and solutions or work arounds to these limitations.

I give this book a rate 10 out of 10 and a big thank to the authors. Of Course I recommend this book as a first choice to those who wish to learn ASP.NET AJAX in deep with simple advanced book.

MSDN Community Distribution June Release

Current June CD release focuses on important fundamentals: Introductory lessons for programming newbies in C# and VB, webcasts on Windows SharePoint Services ("WSS") and Visual Studio Team System ("VSTS") as well as a look at functional programming with F#.

Introductory Lessons
Our starter kit helps to get a foot in the door of today's programming world. Choose an Express Edition and learn how basic Windows applications are created. These lessons focus on the language, object-oriented fundamentals, the Integrated Development Environment ("IDE"), Windows-based user interfaces ("WinForms") and the .NET Framework class library.

Webcasts
The material about Windows SharePoint Services includes:

  • Tips and Tricks for Microsoft Windows SharePoint Services.
  • An Overview of Developer Technologies for Windows SharePoint Services.
  • How to build Collaborative Applications with the Next Version of Microsoft Windows SharePoint Services.
  • How to develop workflows for the 2007 Microsoft Office system and Windows SharePoint Services 2003.
  • How Microsoft IT manages the World's Largest Windows SharePoint Services Deployment.

For Visual Studio Team System we cover the following topics:

  • An Overview of Visual Studio 2005 Team Edition for Software Architects as well as Software Developers.
  • Microsoft Solutions Framework for CMMI Process Improvement and the Standard CMMI Assessment Method for Process Improvement (SCAMPI).
  • Creating and Extending System Definition Models (SDM).
  • Creating Graphical Designers with Domain-Specific Language (DSL) Tools.
  • Extending Visual Studio 2005 Team Foundation Server.
  • Using Visual Studio Team System Process Editor.
  • Load Testing with Visual Studio Team Edition for Software Testers.

Academic Inspirations
Beside the mentioned F# compiler, we present MSR Sense - a networked embedded sensing toolkit, a computer graphics framework for rendering terrains and a technical paper on exploiting graph symmetry to compute the fastest mixing Markov chain.

Downloads:

Posted: Jun 17 2007, 07:33 PM by mosessaur |
Filed under: ,
The WindowsClient.NET Community Site Launches

WindowsClient.net, the community learning resource for Windows Forms and Windows Presentation Foundation.

This site focuses on all aspects of rich client development on Windows using the .NET Framework. New content from both the Microsoft product teams and from the community will be added regularly to highlight the many user experience and developer productivity benefits of rich client applications on Windows.

New! Hands-on Labs for Windows Workflow Foundation in C# and VB.NET
Windows Workflow Foundation is the programming model, engine and tools for quickly building workflow enabled applications on Windows. This download is a set of 10 Hands-on Labs for Windows Workflow Foundation in C# and VB.NET versions. These labs are suitable for a .NET developer with 6 months experience who wants to learn about Windows Workflow Foundation. Each lab is approximately 60 minutes of work. The download package includes lab manuals for each lab, pre-requisite files for the labs and sample completed solutions for each exercise in the labs
Microsoft ASP.NET Futures (May 2007)
The Microsoft ASP.NET Futures May 2007 (“Futures”) release contains an early developer preview of features providing a wide range of new functionality for both ASP.NET and Silverlight™. The functionality in the Futures release includes early experimental versions of features currently being considered for future versions of ASP.NET and the .NET Framework. The Futures releases assume prior knowledge of the core features of ASP.NET including the previous ASP.NET AJAX Futures January CTP.

Features in this release include ASP.NET Silverlight server controls, new functionality for ASP.NET AJAX Extensions, dynamic data controls, enhancements to dynamic languages, and more
WebResourceAttribute And VB.NET, Not Like in C#!

Three months ago I blogged about System.Web.UI.WebResourceAttribute Issue. Recently in ASP.NET forums I noticed a question about this issue! and in the question it is mentioned that the way I descriped didn't work. I noticed also that the guy was using VB.NET not C# on which I tested my post on

The deference, or the issue came up because C# & VB.Net treat or compile resources in deferent ways -this is my own observation-. Return to the issue post on ASP.NET Forums to know what was exactly the problem and how it was resolved.

More Posts Next page »
The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.