PDA

View Full Version : Portal, Portlet & Viewstate



Kalitte
Dec 26, 2008, 6:33 AM
Hi,

We have developed a dashboard application using Portal. With version 0.6, everything was OK. In version 0.7, there are two issues.


void AddWidgetToAnchorLayout(Portlet w, AnchorLayout layout, int position)
{
Anchor an = new Anchor();
an.Horizontal = "100%";
an.Items.Add(w); //-> if we add at the end, we get jscript error.
if (position > layout.Controls.Count)
position = layout.Controls.Count;
if (position >= 0)
{
layout.Controls.AddAt(position, w);
layout.Anchors.Insert(position, an);
}
else
{
layout.Controls.Add(w);
layout.Anchors.Add(an);
}
//an.Items.Add(w); ->this was working with 0.6
}

Second issue is, maybe more important, viewstate of the user control loaded inside (BodyControls) portlet is lost. In version 0.6 we have tested everything and it was working. We want to figure out what the problem is with this new release. Usercontrol saves the state to the viewstate (we have tested it with a viewstate parser) but cannot load viewstate data. There is no error, just viewstate is lost

Vladimir
Dec 26, 2008, 1:21 PM
Hi Kalitte,

I made some test with UserControl ViewState and I can't reproduce bug
Here is my test case

Page.aspx


<%@ Page Language="C#" %>
<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>

<%@ Register src="UCTest.ascx" tagname="UCTest" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" StateProvider="None" />

<ext:ViewPort ID="ViewPort1" runat="server">
<Body>
<ext:BorderLayout ID="BorderLayout1" runat="server">
<Center MarginsSummary="5 5 5 0">
<ext:TabPanel ID="TabPanel1" runat="server" ActiveTabIndex="0" Title="TabPanel">
<Tabs>
<ext:Tab ID="Tab1" runat="server" Title="Tab 1">
<Body>
<ext:FitLayout ID="FitLayout1" runat="server">
<ext:Portal ID="Portal1" runat="server" Border="false">
<Body>
<ext:ColumnLayout ID="ColumnLayout1" runat="server">
<ext:LayoutColumn ColumnWidth=".33">
<ext:PortalColumn
ID="PortalColumn1"
runat="server"
StyleSpec="padding:10px 0 10px 10px">
<Body>
<ext:AnchorLayout ID="AnchorLayout1" runat="server">
<ext:Anchor>
<ext:Portlet ID="Portlet1" runat="server" Title="Another Panel 1">
<Body>
<uc1:UCTest ID="UCTest1" runat="server" />
</Body>
</ext:Portlet>
</ext:Anchor>
</ext:AnchorLayout>
</Body>
</ext:PortalColumn>
</ext:LayoutColumn>
<ext:LayoutColumn ColumnWidth=".33">
<ext:PortalColumn
ID="PortalColumn2"
runat="server"
StyleSpec="padding:10px 0 10px 10px">
<Body>
<ext:AnchorLayout ID="AnchorLayout2" runat="server">
<ext:Anchor>
<ext:Portlet ID="Portlet2" runat="server" Title="Panel 2">
<Body>
<ext:Button runat="server" AutoPostBack="true" Text="PostBack">
</ext:Button>
</Body>
</ext:Portlet>
</ext:Anchor>
</ext:AnchorLayout>
</Body>
</ext:PortalColumn>
</ext:LayoutColumn>
<ext:LayoutColumn ColumnWidth=".33">
<ext:PortalColumn
ID="PortalColumn3"
runat="server"
StyleSpec="padding:10px">
<Body>
<ext:AnchorLayout ID="AnchorLayout3" runat="server">
<ext:Anchor>
<ext:Portlet ID="Portlet4" runat="server" Title="Panel 3" />
</ext:Anchor>
</ext:AnchorLayout>
</Body>
</ext:PortalColumn>
</ext:LayoutColumn>
</ext:ColumnLayout>
</Body>
</ext:Portal>
</ext:FitLayout>
</Body>
</ext:Tab>
</Tabs>
</ext:TabPanel>
</Center>
</ext:BorderLayout>
</Body>
</ext:ViewPort>
</form>
</body>
</html>


UCTest.aspx


<%@ Control Language="C#" %>
<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
this.ViewState["test"] = "test";
}

Label1.Text = this.ViewState["test"] as string;
}
</script>

<ext:Label ID="Label1" runat="server"></ext:Label>

Kalitte
Dec 27, 2008, 9:15 AM
 Hi Vladimir,

I read the instances from database and create portlets at runtime. I read the usercontrol path, column index, create portlet, create usercontrol and add it to the BodyControls collection. Then add the portlet to the AnchorLayout.


After I have upgraded to 0.7, viewstate totally lost. I have implemented IStateManager for the usercontrol and do the usual manual viewstate management (Trackviewstate, LoadViewstate, SaveViewstate etc). Viewstate is now OK for the values I have added with Viewstate["xxx"] = "yyy"; But the viewstate of the controls on the usercontrol (controls of the usercontrol are not dynamic) is lost after a regular/async postback with UpdatePanel. BTW, Portal is inside an UpdatePanel. I have debugged the code, when using v0.6, in Page_Load method of the usercontrol Viewstate is applied to the controls, even uc does not implement IStateManager. So I can get the values, ie. Label1.Text. If I switch to V0.7, in Page_Load property values are empty.


Did you make a change with the viewstate mechanism with version 0.7 ? I am sure my code architecture is correct because if I use asp.net panel instead of Portal &amp; Portlet control (AnchorLayout) it just works as expected and Viewstate is restored.



Kind regards.

Vladimir
Dec 29, 2008, 6:30 AM
Hi,

I made example which loads user control dynamically. The ViewState is restored successful still

Could you change it to reproduce the problem?

Test.aspx


<%@ Page Language="C#" %>

<%@ Import Namespace="Coolite.Utilities" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Anchor an = new Anchor();
an.Horizontal = "100%";

Portlet portlet = new Portlet();
portlet.Title = "Portlet1";
an.Items.Add(portlet);

Control uc = this.LoadControl("UCTest.ascx");
portlet.BodyControls.Add(uc);

AnchorLayout1.Anchors.Add(an);
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Portal in TabPanel - Coolite Toolkit Example</title>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" />
<ext:ViewPort ID="ViewPort1" runat="server">
<Body>

<ext:FitLayout ID="FitLayout1" runat="server">
<ext:Portal ID="Portal1" runat="server" Border="false">
<Body>
<ext:ColumnLayout ID="ColumnLayout1" runat="server">
<ext:LayoutColumn>
<ext:PortalColumn ID="PortalColumn1" runat="server" StyleSpec="padding:10px 0 10px 10px">
<Body>
<ext:AnchorLayout ID="AnchorLayout1" runat="server">
</ext:AnchorLayout>
</Body>
</ext:PortalColumn>
</ext:LayoutColumn>
</ext:ColumnLayout>
</Body>
</ext:Portal>
</ext:FitLayout>
</Body>
</ext:ViewPort>
</form>
</body>
</html>



UCTest.ascx


<%@ Control Language="C#" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
Button1.Text = "PostBack";
this.ViewState["PageTitle"] = "Page Title";
}

this.Page.Title = this.ViewState["PageTitle"] as string;
}
</script>

<ext:Button ID="Button1" runat="server" AutoPostBack="true"></ext:Button>

Kalitte
Dec 30, 2008, 5:27 AM
 Hi Vlademir,

After 7 days study I have found the problem. You're right, the example you sent works but bug is different.



I have inherited Widget class from Portlet and added some functionality, tested the application and works good with v0.6. Bug about the V0.7 is [ViewStateModeById()] attribute. If I remove this attribute from Widget class, everything works.


I think there is a problem in V0.7 with this attribute. 


Thanks for your help.