Blogger Widgets
  • Sharing Photos using SignalR
  • TFS Extenstion - allows copy work items between projects
  • Displaying jquery progressbar with ajax call on a modal dialog
  • Managing windows services of a server via a website
  • Exploring technologies available to date. TechCipher is one place that any professional would like to visit, either to get an overview or to have better understanding.

Search This Blog

Tuesday, 30 November 2010

CSS Cursor as pointer not working

Working on website development for quite a bit now. Just had come across a style sheet issue in a web page. With the following style sheet:-

.linkbtn
{
    cursor:pointer;
    text-decoration: underline;
}

What would anyone expect for this simple html as :

Find

Certainly to show a different cursor when user hovers on the text. Yes it works on IE !! but not on firefox & chrome.

Ok lets debug and see what's happening, the css does show only

.linkbtn
{
    text-decoration: underline;
}

Does'nt make sense at all. does it ? Ok Now I have modifed the html to :

Find

Hurray ! it worked by just re-arranging the class & id attribute.

Three things are certain:
Death, taxes, and lost data.
Guess which has occurred.
~David Dixon, 1998, winning entry of the Haiku Error Messages 21st Challenge by Charlie Varon and Jim Rosenau, sponsored by Salon.com

Tuesday, 23 November 2010

Filename validation in VC++

Validating files names should not be very difficult, Is it? . Yes, it is if you trying to do in VC++. Here is a small snippet of code that helps :-

CString fileName = "test:11";
for (int i = 0; i < fileName.GetLength(); i++)
{
 if (!(PathGetCharType(fileName[i]) & GCT_LFNCHAR)) 
 {
  bValid = FALSE;
  break;
 }
}
Do not forget to include "Shlwapi.h"

“If people never did silly things, nothing intelligent would ever get done.”
– Ludwig Wittgenstein

Friday, 12 November 2010

Display progress bar inside JQGrid

Considered displaying a JQuery progress bar inside JQGrid. Here is a small example how this can be achieved.

Consider the json data returned by a web service is as follows:-

{  
"page":"1",  
"total":1,  
"records":"5",  
"rows":[  
{"id":"1","cell":["1","Scott","US","
10
"]}, {"id":"2","cell":["2","Charles","UK","
20
"]}, {"id":"3","cell":["3","Dan","Astralia","
30
"]}, {"id":"4","cell":["4","Chris","Canada","
25
"]}, {"id":"5","cell":["5","Paul","China","
80
"]} ]}

Here is the script that would achieve the results

jQuery("#grid").jqGrid({  
 url:'GetDetails.asmx?team=All',  
 datatype: "json",  
 colNames:['ID','Name','Country','Progress'],  
 colModel:[  
 {name:'id',index:'id', width:55},  
 {name:'Icon',index:'Icon', width:90},  
 {name:'name',index:'name asc, invdate', width:100},  
 {name:'designation',index:'designation', width:80}],  
 rowNum:10,  
 rowList:[10,20,30],  
 pager: '#pager',  
 sortname: 'id',  
 viewrecords: true,  
 sortorder: "desc",  
 caption:"JSON Data"  
}); 

$('div.progBar').each(function(index) {
    var progVal = eval($(this).text());
    $(this).text('');
    $(this).progressbar({
  value: progVal
 });

});

JQGrid would display the required results and once done update the JQGrid cell data with the progress bar required.



“In a room full of top software designers, if two agree on the same thing, that’s a majority.”
– Bill Curtis

Thursday, 11 November 2010

Display Icons in JQGrid

JQGrid is one of the best plug-in to display data as grid. Using JQGrid is very simple and easy to use. In this article we will look into displaying icons in JQGrid.

Consider the following code that makes an ajax call:

jQuery("#grid").jqGrid({
  url:'GetDetails.asmx?team=All',
 datatype: "json",
    colNames:['ID','Team', 'Name', 'Designation'],
    colModel:[
     {name:'id',index:'id', width:55},
     {name:'Icon',index:'Icon', width:90},
     {name:'name',index:'name asc, invdate', width:100},
     {name:'designation',index:'designation', width:80}],
    rowNum:10,
    rowList:[10,20,30],
    pager: '#pager',
    sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    caption:"JSON Data"
});

The return data from the GetDetails.asmx should be in json format and the data should look like :-

{
"page":"1",
"total":1,
"records":"5",
"rows":[
{"id":"1","cell":["1","","Scott","Manager"]},
{"id":"2","cell":["2","","Charles","Accountant"]},
{"id":"3","cell":["3","","Dan","Sales"]},
{"id":"4","cell":["4","","Chris","Administrator"]},
{"id":"5","cell":["5","","Paul","Developer"]}
]}

The data cell value should contain an image location so that JQGrid will render and display an image in the grid.

“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
– Benjamin Franklin

Wednesday, 10 November 2010

Getting 401 Unauthorized error consistently with jquery call to webmethod

ASP.NET with JQuery provides a flexible method of making ajax calls via a webservice. Making an ajax call using JQuery API would be as simple as

 $.ajax({
            url: "TestService.asmx/Test",
            data: "{'JSONData':'" + JSON.stringify(id) + "'}", // For empty input data use "{}",
            dataType: "json",
            type: "POST",
            contentType: "application/json",
            complete: function (jsondata, stat) {
                if (stat == "success") {
                    var response = JSON.parse(jsondata.responseText).d;
                    $("#divItem").html(response);
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {

            }
        });

Now the webservice method definition should look like:-

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Test(string JSONData)
{
   return JSONData + " Test Data";
}

Now that we have the code ready, lets try to run this. Oh No!! ASP.NET bounced back with following error.

"401 Unauthorized"

This internally means JQuery Ajax call had responded as System.InvalidOperationException and hence that would be thrown as 401 Unauthorized exception.

The simple solution is to include the following line before the class definition of the webservice

[System.Web.Script.Services.ScriptService]


“Real knowledge is to know the extent of one’s ignorance.”
– Confucius

Monday, 1 November 2010

Unable to debug published ASP.NET website

Have been struggling to debug ASP.NET application but had no success what so ever. For time being drop the thought of publishing the website using Visual Studio (2005/2008/2010).

Lets start with the Manual process :-

1. Create a folder under C:\inetpub\wwwroot for eg: MyWebsite
2. Goto IIS, right click on Default Website -> Select Add application
3. Specify Alias, select location, select the required application pool and select OK
4. Now goto Visual Studio, right click on the website -> Publish
5. Go back to IIS and select the application created "MyWebsite"
6. double click on Authentication
7. Now select the following:-
- Anonymous (Enabled),
- Impersonation (Disabled),
- Basic (Disabled),
- Digest (Disabled),
- Forms (Enabled)
- Windows (Disabled)
Note: Assuming web.config is configured to use forms authentication
8. Restart default website.

All of this seems quite easy and looks very familiar. But a small mistake in configuring correct authentication might lead to frustrating situations.


The more you know, the more you realize you know nothing.
– Socrates

Server.GetLastError() giving error as 'File does not exist.'

In general Server.GetLastError() is the more used way of getting the last generated error. But have you ever got an error message and does not exactly know what went wrong. Such as the error below:-

{"File does not exist."}

which has actually occurred in the source code at

protected void Application_Error(Object sender, EventArgs e)
{
    HttpException Error = Server.GetLastError() as HttpException;
    Session["Error"] = Error;
    Response.Redirect("Error.aspx", true);
}


The error by itself is self explanatory that says a file is missing and might be because of an .aspx, .gif, .js file missing or does not have permission to read the file.

Well finding the cause for this might look daunting when you see it. But its very simple, just follow these steps :-

1. Set a breakpoint at the Server.GetLastError()
2. Now open quickwatch
3. Type Request.CurrentExecutionFilePath

this should give the file that is missing. Also this might generally occur at places such as binding a data grids where an image is bound to a column.

The first rule of intelligent tinkering is to keep all the pieces. -Aldo Leopold
Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers