Profiledehran's placeBlogLists Tools Help
Occupation
September 02

A Lap Around Visual Studio 2005

Yesterday, I attended an MSDN session on Visual Studio 2005  at Exchange Room of Microsoft Philippines in Enterprise Tower. It was surprising to see Stanleys presentation was actually his presentation last January TechFest. I came also to meet Heezen, my previous clasmate back in college.
 
I've been playing around with VS2005 for quite some time and his prezo was one of the things that teased me. :)
 
 
September 01

Getting @RETURN_VALUE and Ouput Parameter

To do a custom paging solution for search feature that return large resultset, I need to pass the search string, current page number, the page size to the stored procdure which in turn return the total number of records  qualified and the first batch records within the range of current page and page size. But whatever i do I cannot get the value of the output parameter which holds the value of total records, even if I use @RETURN_VALUE, still it didnt work.

I scan my code and I observe that I'm have not yet close my DataReader before I get the value of my output parameter. By closing my datareader, my code works now.

August 29

Smart Navigation: Maintain Scroll Position Across PostBack

It is pretty annoying to always scroll down or scroll up just to go my previous scroll position after postback. If its a usability test, the application would probably fail! :) Lucky i am, i have a mouse with scroll button but how about our users? 
 
ASP.Net provide way of easing the burden of developers by providing the attribute SmartNavigation = "true" on the Page directive.  Setting it to true will automatically maintain scroll position across postbacks. However, i tried this several times but it crahes my app also several times. I have read that it conflicts with my CSS.
 
A great work by Steve Schuler http://aspnet.4guysfromrolla.com/articles/111704-1.2.aspx provide a good solution for this, however it seems i can't make it work on ASP.net 2.0 pages with a Master Page. As I drill down to his codes and scripts generated by ASP.Net runtime, i found that the GetServerForm(Page.Controls) method cannot resolve the form contained on my Master Page.
As evidence,

<script language = "javascript">
<!--
  function sstchur_SmartScroller_GetCoords()
  {
    var scrollX, scrollY;
    if (document.all)
    {
      if (!document.documentElement.scrollLeft)
        scrollX = document.body.scrollLeft;
      else
        scrollX = document.documentElement.scrollLeft;

      if (!document.documentElement .scrollTop)
        scrollY = document.body.scrollTop;
      else
        scrollY = document.documentElement.scrollTop;
    }
    else
    {
      scrollX = window.pageXOffset;
      scrollY = window.pageYOffset;
    }
    document.forms[""].ctl00_scrollLeft.value = scrollX;
    document.forms[""].ctl00_scrollTop.value = scrollY;
  }


  function sstchur_SmartScroller_Scroll()
  {
    var x = document.forms[""].ctl00_scrollLeft.value;
    var y = document.forms[""].ctl00_scrollTop.value;
    window.scrollTo(x, y);
  }
  
  window.onload = sstchur_SmartScroller_Scroll;
  window.onscroll = sstchur_SmartScroller_GetCoords;
  window.onclick = sstchur_SmartScroller_GetCoords;
  window.onkeypress = sstchur_SmartScroller_GetCoords;
// -->
</script>


A simple tweak may solve the problem. Since ASP.net 2.0 uses "aspnetForm" as name of the form generated from master page and even if you have set the form ID explicitly, still the generated client ID wil be aspnetForm. I changed the GetServerForm() method to return null  instead of a new HtmlForm.

        private HtmlForm GetServerForm(ControlCollection parent) {
            foreach (Control child in parent) {
                Type t = child.GetType();
                if (t == typeof(System.Web.UI.HtmlControls.HtmlForm))
                    return (HtmlForm)child;

                if (child.HasControls())
                    return GetServerForm(child.Controls);
            } return null;
        }

protected override void OnInit(EventArgs e) {
            string theForm_clientID = (_hasMasterPage) ? "aspnetForm" : GetServerForm(Page.Controls).ClientID;

...
}
 
References and Credits:
August 26

Avoid using DOT <.> separator on class names on ASP.Net 2.0

Avoid using DOT <.> separator on class names on ASP.Net 2.0

This happen to me as i tried to run our existing web apps built on asp.net 1.1 on asp.net 2.0.

 

Replicate Error:

Using VS.Net 2005 beta 2, I create a new website. I added a new web form. On file name field entered,

lisa.serv01_manageresource.aspx. Check Place Code on Separate file.

 

Error List:

Error 1 e:\web projects\lisa.6.00\lisa.serv01_manageresource.aspx.cs(12): error CS1514: { expected / 
Error 2 { expected E:\web projects\lisa.6.00\lisa.serv01_manageresource.aspx.cs 12 26 E:\web projects\lisa.6.00\
Error 3 Invalid token ':' in class, struct, or interface member declaration E:\web projects\lisa.6.00\lisa.serv01_manageresource.aspx.cs 12 49 E:\web projects\lisa.6.00\
Error 4 Invalid token '{' in class, struct, or interface member declaration E:\web projects\lisa.6.00\lisa.serv01_manageresource.aspx.cs 13 1 E:\web projects\lisa.6.00\
Error 5 The namespace '<global namespace>' already contains a definition for 'lisa' E:\web projects\lisa.6.00\lisa.serv01_manageresource.aspx.cs 12 22 E:\web projects\lisa.6.00\


 

Work around:

Rename your code-behind class names or replace the DOT separator with underscrore or any other valid charaters. When you renamed your classes, you also have to change the value of Inherits attribute of the Page directive.

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="lisa.serv01_manageresource.aspx.cs" Inherits="lisa.serv01_manageresource" Title="Replicate Error" %>

 

 If your class names was bounded by your company's coding standard, i guess you have talk them.

Also if you'll shift your code-behind model to in-line model, this may fix the problem. he he he

 

More Information:

http://msdn.microsoft.com/asp.net/migration/upgrade/default.aspx

August 25

Curious?

You might wonder why i had series of post on the same day. Well these are all Draft i saved before, i just felt tired to post them and got too busy this past month. How i wish also MSN Spaces could use the Draft date as date instead of the date posted or there could be an option which to use.

Microsoft Kaakbay Event

Early this morining we have attended the Microsoft Kaakbay event at Makati Sports Club. It's nice to see those people from MS very lively and puro comedy. The concept of the event was very good, they called it the Kaakbay Channel if im not mistaken.

 I forgot to bring a camera and my cell was dead that time, poor me, i have no pics to post.

It was a head shot!

I had a chance to watched the movie If Only with my girlfriend and I had heashot that day. It strikes me really and maybe many of us. Well, i have to say to her but just "Happy birth day dear!"
 
As it was stated in the ads, "Panoorin nyo at ng malaman nyo bakit pinaguusapan ang pelikulang ito"

Is It Possible White Hacking IE Autocomplete?

Have you tried to auto populate those textboxes in IE? Once we enter text on those textboxes on IE, next time we use that same field  a drop down list will appear displaying all entries we previously entered [auto complete feature]. Can we do that using ASP.Net or any other way possible say javascript, so I can cache the default contents of those controls. next time the user use that web form, even these are textboxes will serve just like dropdownlist control.

It is sort of autocomplete, but the entries will be comming from sequel server 2000, since we dont want to use list type controls we chose to purely create the application using  textboxes only  but i need to hack the browser to pre-set the entries textbox history list.

as  much as possible i dont want to use  listbox and drop down list, they are hard to use, but with same as  Google Suggest feature but items will be comming from the database and will not be using Xmlhttrequest.

For example, there's supplier textbox, normally, we tend to browse or select from the list but what if there's a big number of suppliers, its not user friendly. If its grid based  user need to search first, then i need to implement paging etc. and they dont want it to be like that. So the requirements is, pure textboxes but with autocomplete feature.

Default: microsoft philippiness, microimage philippines, microdata philippines, microtrend philippines, microcore philippines
Previously entered items: microfocus philippines, micropro philippines

When i focus on supplier textbox, when i type word "micro", the autocomplete should display the combination of Default + Previously entered items.

Now if the user clears the cache, no problem because next time he open the browser the Default already contains the Default + Previously entered items.
some codes i evaluated uses javascript but with different implementation coz they tend to trap the autocomplete feature of IE, so only those items they define will be displayed on  list not the combination of the two.

Deafult items will be updated each time the user open the browser, i expect the user browser to be opened just once or twice and left open for whole working day.

 

My idea might be a great feature for web apps but seems not workable in plain. An image below is a sample I created based on ObjectGraph's sample which uses AJAX technique. Plain javascript is not possible i think, well using array can be but this will be a ++KB to the page to be downloaded to the client. And i am just a javascript trying hard...

 

ANSWER: NO.

If only IE could expose some interfaces for this, i believe it will do but surely will be trapped if secutiry reasons would be concern.

Another, those items we previously entered was maintained in the Temporary Internet Files folder which will be trashed once the user cleans up his computer or the system resources gets low.

OnItemCommand not firing on repeater control

Just this afternoon I am creating the main transaction module for my project, it was my first project with ASP.Net and I'm using .Net 2.0 and ASP.Net 2.0 Beta Edition.

The GUI designer required me to have a collapsable interface just like GMail conversation, so i think best choice is to use a Repeater control. The transaction entries work fine but when i began to create the collapse code using the OnItemCommand event of repeater control the problem begins. OnItemCommand of repeater control does not fire the event raised by Button. I check out the web and this is very interesting:

http://scottonwriting.net/sowBlog/posts/1263.aspx

http://scottonwriting.net/sowblog/posts/1268.aspx

 

Wheww!!! And now i realy have to look again at my ASP.Net Page Life Cycle diagram posted on my side. The problems boils down to how asp.net handles the posted data. 

 

Accoring to MSDN Documentation: Note If you call the DataBind method of the parent control (the DataList, Repeater, or DataGrid control), the ItemCommand event is not raised, because the contents of the parent control are reset. Therefore, you generally do not want to call the DataBind method on each round trip (that is, in the page initialization without checking for a post back).

 

For now, I  placed my databinding code on Page_Init event and I think i realy have to depend it or I'll just use an Image buttom or link button instead.

 

I'll get back once i have the final solution.

Sql Server UDF: convertToProperCase

Just want to share this to you. This might be not so good or optimize in a DBA point of view but definetly helped me presenting db data to users especially when the labels of field on your web site was bounded to db and data are in All CAPS or the All LOWER case.

CREATE FUNCTION udf_pretty(@inputString varchar(4000))
RETURNS
 varchar(4000)
BEGIN
 DECLARE @outputString VARCHAR(4000)
 DECLARE @minChar int
 DECLARE @maxChar int
 
 SET @outputString = ' '+LOWER(@inputString)
 SET @minChar = 97
 SET @maxChar = 122
 WHILE @minChar <= @maxChar
  BEGIN
    SET @outputString = REPLACE(@outputString, ' '+CHAR(@minChar),' '+UPPER(CHAR(@minChar)))
    SET @minChar = @minChar + 1
  END
 RETURN @outputString
END
 
 
 
 
June 17

Step Two: To Specialize

On july 01, 2005 i'll take another step of my career as im going to specialize on Microsoft Technologies mainly on .NET platform.

Banners in websites, what's the logic behind?

 Banners in websites, what's the logic behind? How do these websites and ecommerce companies manage banner/links advertisements. How do they hanlde banner statistics? Do they have an external repository for counting number of times an advertisement was shown?

Ok, im a customer who signed up with you for having my product advertised on your site? What's the agreement behind? Is it that simple as we have an agreement my banner will be shown 1000 times in week? How can can I be so sure?

I'll update this entry once i got accurate information. I have a similiar post on our local developer forum here in the philippines.

May 11

Exception during Reflection

Sometimes trapping an exception that was thrown during reflection can be tricky. I encountered this many times and it happens that the message being displayed is not the actual exception message. To simplify debugging, here comes the Quick Watch window. Its not new anyway but it defintely help me digging down the inner exception down to its root. Module window also helps me a lot.

Many of experience an exception that just display "HRESULT #####", ussualy when using COM Interop. Ha ha , its difficult most of the times.

May 03

ISnapinable Interface

I recently conduct a through  study on Microsoft Management Console. MMC is one windows components that i realy admire for its flexibility and power. I run to Code project and MSDN and found useful information on doing snapins and exploring interfaces implemented to be a snapin-able component.

I created a simple project that mimics  these functionalities but limited features only. The Framework Management Console, a program unit that cetralizes the maagement of my Application Framework. I apoloze for loosing originality but the interfaces is just the same as the MMC but limited features.

Now, i named my first shared interface as ISnapinnable and my co-developer laughs when he saw it.... Nakakatwa talaga pangalan ng interface but i ca'nt think of any that time. It can't be IPlugin maybe ISnapin will do.

As an Analyst/Programmer

I was wondering why many developers dont want to do documentations.
They always run into coding and start writing once some basic requirements have been defined.
This situation usaully happens in non-software companies where developers do analysts work also.

For me documentation must be strictly checked and verified by systems analyst, with developers, and managers. Complete specifications, design guidelines and requirements must be identified beforehand. It saves money and time. Problems identified beforehand can be addressed before production starts. Budget can be allocated. Proposals can be served and reviewed. Thus poducing quality product at lesser development cost.

As an system analyst/programmer, i am tasked to do both coding and requirements gathering and specification. Today i started documenting my project, though not in ISO Standard way or CMM level i believe other developers can understand and implement things that i have written to. I spent whole day and i think i would took a week to finish all these documentation works. Documentation brings me to level and point of view of reader. You dont write manual for developers, you write for users so why dicusing those interfaces, abstract classes etc.... Evrything must be straightforward and procedural.
Reverse goes to administrators, i documentations for administration and set up guide. How - to's approach works better for me..

 

April 21

What's wrong with these CHM?

i was wondering what's happenig with these ebooks that when i copy/move them to other directory, the file gets corrupted. Pages shows blank white but the TOC is still there. When i move them back, it works fine. Some ebooks that i move are ok, but some are not.... am i missing something about Compiled Help File...

Effective C#: Great book!

I finally got a copy of Efective C# 50 Ways to Improve Your C# by Bill Wagner and starting to read it, well im just a few points yet but the book was realy impressive and educating; maybe for both experienced and beginners. Reccomendations are concrete, clear, and justified through examples. Im excited i can can finish it this week. hopefully...

Constants or Public static fields

Constants and public static readonly fields are two ways of declaring constant objects/types but the latter is more preferable and must be used as much as possible. In my Effective C# book, it explains many advantages of using public static readonly fields over const up to the IL level. The rule is if you are sure that the value of that type will never change, use const. I reccomend you to grab a copy of it...

CruiseControl.NET from Scratch? How tos...

After reading an MSDN Mag article about automated buid and Continuous integration and reading the book Open Source Development in .NET, i got interested in evaluating Open source tools like CruiseControl.NET, log4net, etc... At first, CruiseControl.NET installtion was bit painful to me because i had some problems with my configuration files maybe im too sleepy that time, it was 3:00 AM. But after reading the documentation and with the help of my co-developer who's been using ANT, i finally make it runnig.