Hints And Tips research knowledge archive
Tip# 386
Sponsored Links
 
Subject: ASP.NET 2.0 Beta 2 Client Scripting callback ERROR fix!
Updated: Oct-1-2005
Rating: Not Rated
By: Rocky Moore - Member #: 1
Location: Klamath Falls, Oregon USA
Website: www.RockyMoore.com
Category: Computers > Programming > .NET > ASP.NET
Rate This Tip (10=Great):  1  2  3  4  5  6  7  8  9  10
I have battled a bit with an error generated by using browsers other than Internet Explorer.  When you attempt to use client-side scripting callbacks, it will add a script call of:

-------
<script type="text/javascript">
<!--
var pageUrl='/testcategories.aspx';
WebForm_InitCallback();// -->
</script>
-------

to the end of your page.  This will call an embedded script which causes a javascript error of:

------------
Error: element.children has no properties
Source File: http://ourlocalarea/WebResource.axd?d=BND7DT--mO3aZrOOFApLDg2&t=632522017338437500
Line: 144
------------

This is claimed to be an error in the Visual Studio Beta 2 version and is said to be fixed for the release version.  Until then (or until you get the release version), here is a slightly modified solution posted in message form:

http://www.thescripts.com/forum/thread153063.html

By Mikael Svenson

------------------

If I used the code supplied, it would still call the "WebForm_InitCallback()" the moment the page loaded creating the error anyway.  I also did not like having to change the server side code to call the "prepare" function.  So, to simplify the solution, I used this in the head of the page (could have used it at the footer):


<script language="Javascript">

function PrepareForPost()
{
   __theFormPostData='';

   var count = theForm.elements.length;
   var element;
   for (var i = 0; i < count; i++) {
      element = theForm.elements[i];
      var tagName = element.tagName.toLowerCase();
      if (tagName == "input") {
         var type = element.type;
         if (type == "text" || type == "hidden" || type == "password" ||
            ((type == "checkbox" || type == "radio") &&
             element.checked))  {
               __theFormPostData += element.name + "=" +
               WebForm_EncodeCallback(element.value) + "&";
             }
         }
         else if (tagName == "select") {
           var children;
           if( typeof element.children == 'undefined' ) {
             <!-- We are using mozilla -->
             children = element.childNodes;
           }
           else {
              <!-- we are using IE -->
              children = element.children;
           }

           var selectCount = children.length;
           for (var j = 0; j < selectCount; j++)  {
              var selectChild = children[j];
              if ((selectChild.tagName.toLowerCase() == "option") &&
                 (selectChild.selected == true)) {
                       __theFormPostData += element.name + "=" +
                        WebForm_EncodeCallback(selectChild.value) + "&";
                    }
                }
            }
            else if (tagName == "textarea") {
                __theFormPostData += element.name + "=" + WebForm_EncodeCallback(element.value) + "&";
       }
    }
}
     
</script>



And at the bottom of my Aspx page, the last line before "</form>",  I put:


-----

<script type="text/javascript">
<!--
var pageUrl='/testcategories.aspx';
function WebForm_InitCallback()
{
  PrepareForPost();
}
// -->
</script>

-----

This solved the problem and the call is never made to the WebForm_InitCallback().  It seems that this version works with IE or Firefox, so no need for the original.  So far no side effects that I noticed.

[Submit DIGG for this tip]


-----------
Note: Use the tips posted on this site at your own risk. The tips are posted by the public and as such may or may not be valid.

Sponsored Links
Categories
hints and tips gold divider
Sponsor Sites To Visit
The Awakening
Spirit-Filled Christianity is
more than filling a pew !

Not producing fruit?
Healing, where to turn?
Provision, where to turn?
Lost, where to turn?

It is time for --TheAwakening !
The Saints In Light
Christian Thoughts on
Various Topics - Check it Out!

Click Here
Silverlight City

Keep up with the latest in
Microsoft's Silverlight
Technology!

Click Here
Our Local Christians
Find other Christians
In your local area
Who share your beliefs!

Click Here
United Christian Voters
Tired of seeing your
Rights Vanish?
If all Christians would
Pull together, we can
bring Change Unite Now!

Click Here
Reflected Thought
Inventions ~ Ideas ~ Humor
Politics ~ Opinions ~ Thoughts
Software Development
Business And Stuff....

Click Here
HintsnTips.com
Articles on Various Topics!

Click Here
XML RSS News Feed For Recently Posted Hints And Tips  RSS Feed
You can now get updates to the Recent Tips section by using RSS. The address is:

HintsAndTips.com/Rss.aspx

* Posting Tips *
To post a Tip, Recommendation or Tips Wanted, simply browse to the category you feel is a best fit for your post (click on the Recommention or Tips Wanted tab if fitting) and then click on "New Post" option.
(C) Copyright 1998-2009 All Rights Reserved By R & J Technologies - www.RJSoft.com