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
Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers