Showing posts with label ive. Show all posts
Showing posts with label ive. Show all posts

Monday, March 26, 2012

PageRequestManagerParserError in IE6 and 7

Hi,

I've created a pretty simple custom control that filters items based on categories the user selects in a drop down box.
Here's the error I'mintermittently getting in IE6 and IE7 but not any mozilla-based browsers.

error

Because of it's intermittent nature it seems like something out of my control...
I've made sure there are no Response.Write(), Response Filters, HttpModules running and that server trace isn't enabled.

I've used Fiddler to look at the responses but can't find the offending part in the error message.

I've googled the error and found this:

http://forums.asp.net/p/1037846/1437627.aspx

I am using a VirtualPathProvider to map requests to items in a cms, but the article above deals with an incorrect formaction being returned in the httpmessage. I've checked the formaction being returned and it is correct.

I'm at a loss. This is a real pain because a lot of time has been invested in using Asp.Net Ajax for our new site and this may make us have to rethink that decision.

Here is the code for my custom control.

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Collections;

using System.Collections.Generic;

using System.Text;

namespace Unwrong.Controls

{

publicclassFilterList :Control,INamingContainer

{

privatestring _Category;

privateList<FilterListItem> _Items =newList<FilterListItem>();

privateint _MaxVisibleItems;

privateint _Position = 0;

privatestring _CssClass;publicstring Category

{

get {return _Category; }

set { _Category =value; }

}

publicList<FilterListItem> Items

{

get {return _Items; }set { _Items =value; }

}

publicList<FilterListItem> ItemsInCategory

{

get {return GetItemsInCategory(); }

}

publicint MaxVisibleItems

{

get {return _MaxVisibleItems; }

set { _MaxVisibleItems =value; }

}

publicint Position

{

get {return _Position; }set { _Position =value; }

}

publicstring CssClass

{

get {return _CssClass; }

set { _CssClass =value; }

}

protectedoverridevoid OnInit(EventArgs e)

{

Page.RegisterRequiresControlState(this);base.OnInit(e);

}

protectedoverridevoid AddParsedSubObject(Object obj)

{

if (objis Unwrong.Controls.FilterListItem)

{

Items.Add((Unwrong.Controls.FilterListItem)obj);

}

}

protectedoverridevoid CreateChildControls()

{

System.Collections.IEnumerator myEnumerator = Items.GetEnumerator();

while (myEnumerator.MoveNext())

this.Controls.Add((FilterListItem)myEnumerator.Current);

}

protectedoverrideobject SaveControlState()

{

FilterListViewstate state =newFilterListViewstate();

state.Category = Category;

state.Position = Position;

return state;

}

protectedoverridevoid LoadControlState(object state)

{

if (state !=null)

{

Category = ((FilterListViewstate)state).Category;Position = ((FilterListViewstate)state).Position;

}

}

protectedoverridevoid Render(HtmlTextWriter w)

{

List<FilterListItem> itemsToDisplay = GetDisplayItems();w.Write(@dotnet.itags.org."<script language='javascript' type='text/javascript'>

<!--

function hide(id){

try{

var obj=$get(id);

obj.style.visibility='hidden';

}catch(e){}

}

function show(id){

try{

var obj=$get(id);

obj.style.visibility='visible';

}catch(e){}

}

//-->

</script>

");w.Write("<div class=\"column1\">");

w.Write(GetItemsInColumn(0));

w.Write("</div>");

w.Write("<div class=\"column2\">");

w.Write(GetItemsInColumn(2));

w.Write("</div>");w.Write("<div class=\"column3\">");

w.Write(GetItemsInColumn(4));

w.Write("</div>");

}

privatestring GetItemsInColumn(int index)

{

List<FilterListItem> items = GetDisplayItems();

// Check if any items are at the necessary indeces.

if (items.Count > index)

{

StringBuilder sbHtml =newStringBuilder();

// Create the html for two projects.

for (int i = 0; i < 2; i++)

{

index += i;

if (items.Count > index)

{

FilterListItem item = items[index];

sbHtml.Append("<div class=\"project\" ");

sbHtml.Append("onmouseover=\"this.style.backgroundColor='#E1E1E1'; hide('" + ClientID +"_title" + index +"'); show('" + ClientID +"_details" + index +"');\" ");

sbHtml.Append("onmouseout=\"this.style.backgroundColor='#FAFAFA'; show('" + ClientID +"_title" + index +"'); hide('" + ClientID +"_details" + index +"');\" ");

sbHtml.Append(">");if (!String.IsNullOrEmpty(item.ProjectLink))

{

sbHtml.Append("<a href=\"" + item.ProjectLink +"\"><img src=\"" + item.Image +"\" alt=\"" + item.Title +"\" title=\"" + item.Title +"\" /></a>");

}

elseif (!String.IsNullOrEmpty(item.LiveLink))

{

sbHtml.Append("<a href=\"" + item.LiveLink +"\" target=\"_blank\"><img src=\"" + item.Image +"\" alt=\"" + item.Title +"\" title=\"" + item.Title +"\" /></a>");

}

else

{

sbHtml.Append("<img src=\"" + item.Image +"\" alt=\"" + item.Title +"\" title=\"" + item.Title +"\" />");

}

sbHtml.Append("<div id=\"" + ClientID +"_title" + index +"\" class=\"title\">");

sbHtml.Append(item.Title);

sbHtml.Append("</div>");

sbHtml.Append("<div id=\"" + ClientID +"_details" + index +"\" class=\"details\">");

if (!String.IsNullOrEmpty(item.ProjectLink))

{

sbHtml.Append("<a href=\"" + item.ProjectLink +"\">View Details</a>");

}

else

{

sbHtml.Append("<span class=\"strikethrough\">View Details</span>");

}

if (!String.IsNullOrEmpty(item.LiveLink))

{

sbHtml.Append("<br/><a href=\"" + item.LiveLink +"\" target=\"_blank\">View Live</a>");

}

else

{

sbHtml.Append("<br/><span class=\"strikethrough\">View Live</span>");

}

sbHtml.Append("</div>");sbHtml.Append("</div>");

}

}

return sbHtml.ToString();

}

else

{

returnstring.Empty;

}

}

privateList<FilterListItem> GetItemsInCategory()

{

List<FilterListItem> itemsInCategory =newList<FilterListItem>();

// Remove all items that aren't in current category.

foreach (FilterListItem itemin Items)

{

if (IsItemInCategory(item))

{

itemsInCategory.Add(item);

}

}

return itemsInCategory;

}

privateList<FilterListItem> GetDisplayItems()

{

List<FilterListItem> itemsInCategory = GetItemsInCategory();

List<FilterListItem> itemsToDisplay =newList<FilterListItem>();

int count = MaxVisibleItems;if (Position + MaxVisibleItems > itemsInCategory.Count)

{

count = itemsInCategory.Count - Position;

}

return itemsInCategory.GetRange(Position, count);

}

privatebool IsItemInCategory(FilterListItem item)

{

if (String.IsNullOrEmpty(Category) || Category.ToLower() =="all")

{

returntrue;

}

foreach (string cin item.Categories)

{

if (c.ToLower().Trim() == Category.ToLower().Trim())

{

returntrue;

}

}

returnfalse;

}

}

[Serializable]

publicclassFilterListViewstate

{

publicstring Category;publicint Position;

}

}

Here is the code for page where it is used:

<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional">

<ContentTemplate>

<tableid="filter-widget-bar"cellpadding="0"cellspacing="0"border="0">

<tr>

<tdclass="col1">

<imgsrc="/assets_new/images/projects.gif"alt="Projects"/>

</td>

<tdclass="col2">

<tableid="filter-widget"cellpadding="0"cellspacing="0"border="0">

<tr>

<td>

<ctrl:ImageButtonID="btnPreviousProject"runat="server"CssClass="previous"ImageUrl="~/assets_new/images/btn_previous.gif"OnClick="btnPreviousProject_Click"BorderWidth="0"AlternateText="Previous"/>

</td>

<td>

<asp:DropDownList

ID="lstFilter"

OnSelectedIndexChanged="lstFilter_OnSelectedIndexChanged"

AutoPostBack="true"

runat="server">

<asp:ListItem>Favourites</asp:ListItem>

<asp:ListItem>All</asp:ListItem>

<asp:ListItem>Games</asp:ListItem>

<asp:ListItem>Websites</asp:ListItem>

<asp:ListItem>Applications</asp:ListItem>

<asp:ListItem>Playthings</asp:ListItem>

<asp:ListItem>Cms</asp:ListItem>

<asp:ListItem>Flash</asp:ListItem>

<asp:ListItem>Html</asp:ListItem>

</asp:DropDownList>

</td>

<td>

<ctrl:ImageButtonID="btnNextProject"runat="server"CssClass="next"ImageUrl="~/assets_new/images/btn_next.gif"OnClick="btnNextProject_Click"BorderWidth="0"AlternateText="Next"/>

</td>

</tr>

</table>

</td>

<tdclass="col3">

</td>

</tr>

</table>

<divid="projects">

<ctrl:FilterListID="lstProjects"runat="server"MaxVisibleItems="6">

<ctrl:FilterListItemrunat="server"Image="repository/uploads/projects/ilovedust.jpg"Title="ILoveDust"ProjectLink="http://www.unwrong.com/projects/ilovedust/"LiveLink="http://www.ilovedust.com">

<ctrl:Categoriesrunat="server">

<ctrl:Categoryrunat="server">Flash</ctrl:Category>

<ctrl:Categoryrunat="server">Cms</ctrl:Category>

<ctrl:Categoryrunat="server">Favourites</ctrl:Category>

<ctrl:Categoryrunat="server">Websites</ctrl:Category>

</ctrl:Categories>

</ctrl:FilterListItem>

<ctrl:FilterListItemrunat="server"Image="repository/uploads/projects/tado.jpg"Title="Tado"ProjectLink="http://www.unwrong.com/projects/tado/"LiveLink="http://www.tado.co.uk">

<ctrl:Categoriesrunat="server">

<ctrl:Categoryrunat="server">Flash</ctrl:Category>

<ctrl:Categoryrunat="server">Favourites</ctrl:Category>

<ctrl:Categoryrunat="server">Websites</ctrl:Category>

</ctrl:Categories>

</ctrl:FilterListItem>

<ctrl:FilterListItemrunat="server"Image="repository/uploads/projects/communicatorworld.jpg"Title="Communicator World"ProjectLink="http://www.unwrong.com/projects/communicator/"LiveLink="http://www.communicatorworld.co.uk">

<ctrl:Categoriesrunat="server">

<ctrl:Categoryrunat="server">Flash</ctrl:Category>

<ctrl:Categoryrunat="server">Cms</ctrl:Category>

<ctrl:Categoryrunat="server">Favourites</ctrl:Category>

<ctrl:Categoryrunat="server">Websites</ctrl:Category>

</ctrl:Categories>

</ctrl:FilterListItem>

</ctrl:FilterList>

</div>

</ContentTemplate>

</asp:UpdatePanel>


Hi,smeeg

This happens when the machineKey used to encrypt/decrypt the viewstate was changed, and more likely this will happen if you keep the page idle for a long time. To avoid this, you need to have a static machineKey.

Check this articlehttp://blog.g9th.com/2007/01/14/unable-to-validate-data-at-systemwebconfigurationmachinekeysectiongetdecodeddata.aspx

Let me know if you need more info.
You can also see this thread for more help:http://forums.asp.net/t/1115331.aspx

Thanks

NOTE:This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

Saturday, March 24, 2012

PageRequestManagerServerErrorException: HtmlTableBodySection cannot have children of type

i've been looking really hard for reason but couldn't find any. I really need help on this:
i have a page with a complex grid inside an update panel -
The grid is a repeater that contains an html table and inside the item template there is also a <tbody> tag that contains another repeater with an html table template.

Now it works great when running locally and on the test server wich is an win 2003 on the local network and it even ran ok on the previously hosted server but on the new one i get this error:
Sys.WebForms.PageRequestManagerServerErrorException: 'HtmlTableBodySection' cannot have children of type 'Repeater'.
and all i can find about this type of error is unrelated to the event in this case.

Can anyone suggest anything here?

ps. the only reason for the tbody is because i need a way to 'minimize' related rows (the rows of the inner repeater) in one click of parent row.

HtmlTableBodySection is a new type for .NET 2.0 SP1, so if you had the Service Pack installed than this should work

Paging With AJAX Using a Datalist.

I've spent a good 6 hours trying to figure this out and came up with nothing... nothing worked nor was it going to. So now I'm posting because I need HELP! I have a datalist that spits out images from a database. Simple enough... now I need only 5 of those images to display at any given time with a next and previous button to flip through all the pics as if they were thumbnails without the page reloading... so thats where ajax comes into play. My problem is that I'm still fairly new to ajax and I've already jumped into asp.net ajax. Does anybody know how I can accomplish this?

The easiest way is using UpdatePanel.

http://www.asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx


I've looked into the updatepanel but I've never used one before. Looks interesting but i'm still confused as to how to use what i have in it to only show 5 images at a time with next and previous buttons. Can someone point me in the right direction?

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
<asp:ScriptManager ID="ScriptManager" runat="server" />
<asp:ObjectDataSource ID="ImageObjectDataSource" runat="server" TypeName="IllumiCell.NorthOfTorontoUG.BLL.Image" OldValuesParameterFormatString="original_{0}" SelectMethod="GetImageDataByAlbumId">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="albumId" QueryStringField="albumId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<script type="text/javascript" language="javascript">
var xmlHttpRequestObject = false;

try
{
// Firefox, Opera 8.0+, Safari
xmlHttpRequestObject = new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
window.location="Default.aspx";
}
}
}

function changeImage(img)
{
if (xmlHttpRequestObject)
{
var obj = document.getElementById("ViewImage");

xmlHttpRequestObject.open("GET", img);

xmlHttpRequestObject.onreadystatechange = function()
{
if(xmlHttpRequestObject.readyState == 4 && xmlHttpRequestObject.status == 200)
{
// The state is complete and the status is successful.
}
}

/*int originalHeight = obj.width;
int originalWidth = obj.height;
int panelWidth = 576;
int panelHeight;

if (originalHeight >= originalWidth)
{
panelHeight = panelWidth * (originalWidth / originalHeight);
panelWidth = originalWidth / (originalHeight / panelHeight);
}
else
{
panelWidth = panelWidth * (originalHeight / originalWidth);
panelHeight = originalHeight / (originalWidth / panelWidth);
}

obj.style.width = panelWidth + "px";
obj.style.height = panelHeight + "px";*/

obj.src = "album/" + img;
}
else
{
alert("Your browser does not support AJAX!");
window.location="Default.aspx";
}
}

function changeDescription(desc)
{
if (xmlHttpRequestObject)
{
var descObj = document.getElementById("objDesc");

xmlHttpRequestObject.open("GET", desc);

xmlHttpRequestObject.onreadystatechange = function()
{
if(xmlHttpRequestObject.readyState == 4 && xmlHttpRequestObject.status == 200)
{
// The state is complete and the status is successful.
}
}

descObj.innerHTML = desc;
}
else
{
alert("Your browser does not support AJAX!");
window.location="Default.aspx";
}
}
</script>
<div style="background-image:url('img/Header.png'); background-repeat:no-repeat; height:50px;
font-family:Verdana; text-align:center; font-size:medium; font-weight:bold; ">
<br />Photos
</div>
<center>
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>

</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="ImageViewPanel" runat="server" Height="432px" Width="576px" BorderColor="white" BorderWidth="5px">
<asp:FormView ID="ImageFormView" runat="server" DataSourceID="ImageObjectDataSource" DataKeyNames="ImageId">
<ItemTemplate>
<img src='album/<%# Eval("AlbumId") %>/<%# Eval("ImageName") %>' id="ViewImage" alt="" />
<div id="objDesc"><%# Eval("ImageDescription") %></div>
</ItemTemplate>
</asp:FormView>
</asp:Panel>
<p /><asp:DataList ID="ImageDataList" RepeatDirection="Horizontal" RepeatColumns="5" runat="server" DataKeyField="ImageId" DataSourceID="ImageObjectDataSource">
<ItemTemplate>
<div style="padding:10px;">
<img src='album/<%# Eval("AlbumId") %>/thumb_<%# Eval("ImageName") %>' onclick="changeImage('<%# Eval("AlbumId") %>/<%# Eval("ImageName") %>'); changeDescription('<%# Eval("ImageDescription") %>')"
alt='<%# Eval("ImageDescription") %>' style="background-color:White;" />
</div>
</ItemTemplate>
</asp:DataList>
</center>
<div style="background-image:url('img/Footer.png'); background-repeat:no-repeat; height:44px;
font-family:Verdana; font-size:medium; font-weight:bold;">
</div>
</asp:Content>


Certainly you can use UpdatePanel for Ajaxifying your Page but the DataList control does not have any builtin paging feature like the GridView or DataGrid. For this you have write your own paging solution or use custom pager developed by others. Checkout the following links:

http://www.codeproject.com/useritems/SmartPager.asp
http://www.codeproject.com/aspnet/CollectionPager.asp
http://www.codeproject.com/aspnet/ASPNETPagerControl.asp

Another solution might if you are only showing pictures you can try the SlideShow of Ajax Control Toolkit.
http://www.asp.net/AJAX/Control-Toolkit/Live/SlideShow/SlideShow.aspx


I still can't figure this out... I've been all over google as well. I can't use the updatepanel... doesn't really seem to work with the datalist (i need the datalist so that i can show 5 columns). And I also need it to be ajax enabled. Does anybody know how they can take a datalist control with 5 columns... cut off the proceeding rows and make it act like a pager without a postback? My heads about to burst!


Hmm... I think I'll give silverlight a try.