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, 26 October 2010

Invalid postback or callback argument on Post back

One of the most familiar error while working on ASP.NET ajax update panels is :-

505|error|500|Invalid postback or callback argument. Event validation is enabled using in configuration or 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.



Well its not quite easy and literally its frustrating to find out the cause. Everything is working fine in IE but not on firefox, chrome etc. So what went wrong is something very simple no one would expect.

Loading a webpage that contains number of user controls and one of which has a dropdown. The dropdown is binded to an array of strings. Now who would expect binding a string array to drop down would go wrong, no one but it does go wrong.

One of the string has a "\r" character which was messing the complete postback. Some how this is handled in IE but not on other browsers.

Any way after investing so much and finding so little to fix was a relief.

It has become appallingly obvious that our technology has exceeded our humanity.

~Albert Einstein

Friday, 22 October 2010

Updating contents of IFrame using JQuery

Now a new challenge !!!

Updating the contents of iframe using jquery, sounds easy as jquery by default provides the option as follows:-

$("#iframe1").contents()

Now that you are able to retrieve the contents, updating data is quite easy. for eg:-

$("#iframe1").contents().find("#mydiv").css("background-color","red");

In order to update the contents of #mydiv in iframe1 first iframe1 should be loaded with another page. Its all seems fine now. Ok but the hard bit is
- No default src provided
- replace the content of iframe completely not just some specific elements

Why not just use standard html method provided by jquery as

$("#iframe1").contents().html('

Test

);

Yes its easy, but no it does not work. Just a small change to make this work.

$("#iframe1").contents().find('html').html('

Test

');

Also another advantage of this is jquery extenstions or plugins work just as easy. For example using highlight plug-in would be

$('#iframe1').contents().find('html').highlight('test');
  $('#iframe1').contents().find('html').find('.highlight').css('background-color', 'yellow');

Hope this should have save some of your time.

The first rule of intelligent tinkering is to keep all the pieces.

Aldo Leopold

Tuesday, 19 October 2010

LoadViewState not firing on post back in custom control

Recently started developing a custom control with complex data handling. So far so good. Now lets try adding view state content to the custom control. Oh no! its not working. What's wrong is there a design flaw or some thing overlooked.

Have been struggling for quite a decent number of hours to fix this. After revisiting the code and looking into event life cycle for ASP.NET .

Ha ha ... yes overlooked a basic detail but have given me a severe headache. Never load any custom control in Page_Load but load them in OnPreInit.

Instead of loading

    protected void Page_Load(object sender, EventArgs e)
    {
       if (!Page.IsPostBack)
       {
       }
    }

load the controls in

    protected override void OnPreInit(EventArgs e)
    {
       if (!Page.IsPostBack)
       {
       }
    }

This very detail can be more daunting after the design had become more complicated.

To err is human, but to really foul things up requires a computer. ~Farmer's Almanac, 1978

Tuesday, 28 September 2010

Displaying jquery progressbar with ajax call on a modal dialog

Working on a website of which one of the requirement is to display a progress bar while completing an ajax call. Yes this is a simple and straight forward requirement and lets look to the details of how to implement it.

1. Create a web service

2. Using jQuery do the following :-
2.1 Show modal dialog box
2.2 show progress bar on the modal dialog box as 0% completed
2.3 Make an ajax call (estimated time of 5 mins)
3. While ajax call is processing make another ajax call to the web service to find the percentage completed and do this using set interval (or) using jquery count down plugin

Now that we have the design aspect, lets start implementing this.

At first an ajax call (ProcessRequest() - webservice method) is made and after 10 secs another ajax call ProcessStatus() - webservice method) is made to retrieve the percentage completed.

AjaxWebService.asmx
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string ProcessRequest()
{
   return AjaxData.AjaxProcess();
}

[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public int ProcessStatus()
{
   return AjaxData.AjaxStatus();
}


AjaxData.cs
public class AjaxData
{
    private static int status = 0;

 public AjaxData()
 {
        status = 0;
 }

    public static string AjaxProcess()
    {
        string retValue = "Started";
        status = 0;
        for(int i=1;i<=100;i++)
        {
            System.Threading.Thread.Sleep(100);
            status++;
        }

        retValue = "Completed Successfully !";
        return retValue;
    }

    public static int AjaxStatus()
    {
        return status;
    }

}
default.aspx (script)

The complete project source code is available on Codeplex

“Physics is the universe’s operating system.” – Steven R Garman

Monday, 13 September 2010

Unable to uninstall: assembly is required by one or more applications

Un-installing from GAC can be done in various methods such as :-

1. Using windows explorer goto C:\Windows\assembly
2. Locate the assembly
3. use delete button (or) right click -> Uninstall

Alternate method is

1. Goto Visual Studio Command prompt
2. type gacutil /u Me.Test.Assembly

If both of these doesn't work then the assembly is used by some of the component. Ok now that you have known that assembly has a dependency but still you want to delete. This might occur in a scenario where in you want to update the assembly with the new version not by having side by side but having only latest version. This can be achieved by clearing some of the entries in the registry. The entry for the assembly can be in one of these two locations:-


HKEY_CURRENT_USER\Software\Microsoft\Installer\Assemblies\Global
(or)
HKEY_LOCAL_MACHINE\Software\Classes\Installer\Assemblies\Global


Locate the entry related to your assembly and delete it, this should remove the dependency. Now just go and uninstall from GAC using either of the two methods above.


The Internet is a minefield of opportunity. Step carefully, or another opportunity will go off right in your face
- Russell Davies

Tuesday, 7 September 2010

Sys._ScriptLoader is null or not an object

Working on a website and have got following error :-

"Sys._ScriptLoader is null or not an object"

Have been using the methodology of downloading multiple javascript files after the visible content. When combine script is enabled the above error is displayed.

The reason for this error being the definition of the following function :-

$type = Sys._ScriptLoader = function _ScriptLoader() {

has not been loaded so need to exclude respective scriptResource.axd during combine scripts mode. Hope this might help to fix some of the issues.

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

Thursday, 2 September 2010

Unable to get readonly textbox value from server side ASP.NET

Unable to get textbox value from server side is not a bug in ASP.NET but is a feature. Textbox value cannot be read from code behind if it is readonly as per MSDN .

But the value can be read using the following syntax :

txtFirstName.Text = Request[txtFirstName.UniqueID];


“The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.”
– Stephen Hawking
Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers