Saturday, December 15, 2007

Excel Like Add Rows Above, Below at client side in Infragistics UltraWebGrid with the help of UltraWebMenu



Infragistics Ultrawebgrid is a popular ASP.NET RAD web grid control which supports creating hierarchical datagrid in a breeze. Its CSOM [Client side Object Model] exposes many client side events which greatly helps to meet any kind of challenging requirements and simply reduces development time. My requirement is to Add Grid Rows Just above [or] below the selected Active row and all the operations should be at client side, just like excel. Unfortunately Infragistics Ultrawebgrid doesn't support this kind of requirement out of the box, It supports adding rows at Top [or] Bottom of the grid not above [or] below any selected active rows [This can be done at server side by attaching UltrawebNavbar control to Ultrawebgrid]

I searched their forum post and googling to achieve this in client side but no luck. I managed to achieve the desired result [XLGrid Sample 1] by manipulating their client side methods, for javascript source code please look view source of the demo page. The demo [ XLGrid Sample 1] is a flat grid [one level] but my requirement is adding rows dynamically for hierarchical grid at all levels [3 level]. I have done it for my project requirement but yet to create a sample to post it here.

How I did:
1. Infragistics supports adding rows on Top / bottom of the grid through javascript igtbl_addNew. I utilized igtbl_addNew to add a new row at the bottom of the grid and simultaneously stored the desired index location where the new row should be added in a page level javascript variable
2. Infragistics also exposes two other methods remove and insert at particular index location. So i utilized those methods i.e. I removed the just added row [bottom most row] using remove method and then reinsert that row in the desired location using insert method.

Internally Infragistics uses remove and insert methods for client side sorting.

Note:
This post is not about the features of Infragistics ultrawebgird, to learn about the usage and features please refer their web site.

ASP.NET AJAX AND ASP.NET 2.0 ERROR: “Invalid postback or callback argument.”

In my current ASP.NET 2.0 [AJAX] project, I came across this error

" Invalid postback or callback argument. Event validation is enabled using <pages enableeventvalidation="true" /> in configuration or <%@ page enableeventvalidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation."

After looking at the error message I immediately set enableeventvalidation="false" at page level and do away with the error but I faced other problem i.e. I was not able to retrieve values of my controls [only specific control] during post back. The scenario goes like this:

My asp.net page has got the following server controls
1. Textbox,
2. Drop down list
3. Button
4. Grid inside an Updatepanel

In the client side onchange event of the textbox control, AJAX web service call is made and based on the result the drop down list gets populated dynamically. Upon button click, my gridview control which is inside the updatepanel should populate [expected result]. I was not able to get the selected value of the drop down list during partial post back and I couldn't find the root cause immediately and at last after googling I got a good pointer about this issue is well explained by Scott Allen

http://odetocode.com/Blogs/scott/archive/2006/03/20/3145.aspx [Part 1]
http://odetocode.com/Blogs/scott/archive/2006/03/21/3153.aspx [Part 2]

At last I managed to get my expected results by introducing an hidden control where I set the dropdown list's selected value through client side javascript code and then able to get the hidden controls value during partial post back [Kind of laborious and dirty way]. Time being the problem was solved. If i come across better approach I'll update this post. If any of you have better solution please suggest.


Friday, December 14, 2007

How To Inject Javascript during partial postback in ASP.Net

Injecting Javascript Codes using ClientScriptManager class i.e. RegisterClientScriptBlock  in asp.net codebehind will not work for partial postback [ASP.NET AJAX Calls].
To make it work we need to use ScriptManager class's ScriptManager.RegisterStartupScript, ScriptManager.RegisterClientScriptBlock methods

Example:

string msg = string.Format("alert('Test Javascript from partial postback');");
ScriptManager.RegisterStartupScript(TestButton, typeof(Button),"Test_my_script",msg, true);

TestButton => The control which triggered the partial postback [It may be other controls which are inside the updatepanel]
typeof(Button) => System.Type object for a type
Test_my_script => any unique string as key
msg => Javascript code to be injected
true /false => Adds javascript script tags i.e. <script></script>

Wednesday, October 24, 2007

Prototype Javascript Framework

"Prototype is a JavaScript Framework that aims to ease development of dynamic web applications.
Featuring a unique, easy-to-use toolkit for class-driven development and the nicest Ajax library around, Prototype is quickly becoming the codebase of choice for web application developers everywhere."


Of Late I had a chance to know about open source JavaScript Framework called Prototype while reading an article "Painless JavaScript Using Prototype". Prototype has been there since 2004 but now a days getting more focus because of AJAX hype. Prototype framework eases the javascript development and also teaches how javascript code needs to be written (i.e. object oriented way of writing). It has plenty of methods and helper functions to manipulate DOM and execute AJAX calls & without the help of prototype, coding those functions would be really tough, time consuming and error prone.

After tasting Prototype, my javascript programming (the way i write javascript code) has been changed tremendously and I could realize the benefits. I strongly recommend my friends who read my blog posts to have a look at
Prototype Framework and start using it in your projects. The API docs of Prototype can be found here here.

Prototype together with
Scriptaculos an add on for Prototype are must have Javascript Libraries.

To get a quick grip on Prototype, read
"Painless JavaScript Using Prototype". I'll also publish web 2.0 (AJAX Enabled) demo applications built using prototype and Scriptaculos. Already I coded a Photo Gallery & Film Strip Demo applications using Prototype, Scriptaculos, ASP.Net Web Services. In the Demo app, I leveraged few powerful prototype methods i.e. Iterators, Templates, Custom Event Binding [Attach & Detach], Calling ASP.NET Web Services From Client Code [With out using ASP.Net AJAX Libraries] etc. Articles on Photo gallery AJAX Demo Application is under way, I'll publish it in a short while.

Wednesday, October 17, 2007

Part 1: LEARNINGS DURING PERFORMANCE OPTIMIZATION EXERCISES in an ERP application development using C# .Net 2005, ORACLE 10g, ActiveReports.Net etc

For the past one month I have been working on Performance (query) optimization exercise for an ERP application for a leading chain of Rental [DVD, VHS, BOOKS, and GAMES] store in JAPAN. We (my company) involved in the development of store front set up, touch panel catalogue search; store administration etc which involves variety of batch processes, multi dimensional reports and the lists goes. It is needless to say about the data structues (Tables) in a complex ERP system, tables are huge in numbers and the data sizes are in the range of millions with nearly 30% data increase per year. The coding phase is almost done [Design and coding consumed more than a year] and currently functional and non functional testing is under way. Lots of performance related issues popping up due to different reasons!! may be overseen in the requirement and design phase [no comments] or due to lack of experience in the ever changing technology and between version changes among products [No software is perfect during design & development and some are even bad after development too!]. Here I would want to share my learnings and experience in this optimization exercise so that this might help others too who are in the same path or at least facilitate them to look their problem in a different perspective.
Though I am mainly focussed on queries, I will not only talk about query in particular here but also the programming language, design approachs & any 3rd party tools used (reporting tools etc) which are tightly coupled with data.

Saturday, October 6, 2007

Japan Railway - Time Table, Course & Fare Search in English

Hitachi Information Systems ,Ltd developed Japan Railway Course & Fare search online tool for foreigners. The tool can be reached here http://grace.hyperdia.com/cgi-english/hyperWeb.cgi

In this tool one need to give the starting and destination point, it gives us the Train Schedules, Fare, distance in Kms, change point so on and so forth... This site should be bookmarked in your favorites.

Japan Maps - Address Search, Place Lookup, Zip Search in English

Travel and address lookup are tedious for foreigners living in Japan because everything in Japanese Scripts [Kanji & kanas]. In Japan they have everything from address look up - driving directions like in America and Europe but not in English. Recently I found a private website http://diddlefinger.com/ offers the following services on top of Google Maps in english labels.
  • English Address Search: Map most addresses in Japan using English.
  • Place Lookup: Look-up many geographical locations in Japan.
  • Zip/Postcode Search: Type in a yubinbango (Zip/Postcode) and you will be taken to the area it relates to. Enter the first 3 digits to go to the approximate area.
  • JP Address: Look-up a Japanese address using standard kanji address entry.
  • Plot Link: Copy and paste a "Google maps" e-mail link here to plot that location on diddlefinger.
  • Sync: Synchronize the map and the web-page. [Useful if you pan/zoom a long way from your starting point and want to make a bookmark. ]
  • Link to page: Get a link you can e-mail/IM of the current map location and any "green arrow" markers.
  • E-mail: Make a link to current page, and any green markers, in your mail client.
I thought I can share this with others who visits /google my blog. I strongly recommend aliens living in Japan to bookmark this link.