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.htmlBy 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.