GridView erroneous behavior on postback

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
3/4/2008 6:33:04 AM
Gravatar
Total Posts 8

GridView erroneous behavior on postback

Hi, I have the following problem:

When postback a page, a gridview is not recreated runing mojoportal on linux (suse 10.2). Running mojoportal on windows works fine.

I tested the case without monoproject (a new web project) and works fine on both linux and windows.

I have reported the case to monoproject (bug 364732), but Im developing now to a customer and I need find a fast response.

Thank you very much for your Help.

The sample code for test:

// gridctrl.ascx.cs created with MonoDevelop
// User: analista at 10:25 29/02/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;
using System.Web;
using System.Web.UI;
using System.Data;


namespace gridviewtest
{


public partial class gridctrl : mojoPortal.Web.SiteModuleControl
{
protected System.Web.UI.WebControls.GridView xgrid;

 

 

protected void Page_Load(object sender, EventArgs e) {

if (!IsPostBack) {
      Populate();
}else{
      // here the grid view must be recreated with viewstate info. Works fine
      // on windows, doesnt anything on linux
}

}

private void Populate(){
DataTable tbl = new DataTable();
tbl.Columns.Add(new DataColumn("Col1"));
tbl.Columns.Add(new DataColumn("Col2"));
for (int i=0;i<10;i++){
DataRow r = tbl.NewRow();
r["col1"]="data-col1-"+i;
r["col2"]="data-col2-"+i;
tbl.Rows.Add(r);
}

xgrid.DataSource = tbl;
xgrid.DataBind();
 

}
}
}
 

 

**** the ascx

<%@ Control Language="C#" Inherits="gridviewtest.gridctrl" %>

<input type="submit" />
<p>
<asp:Label id="lblStatus" runat="server" >
Submit doesnt show the gridview (like if gridview.EnableViewState="false")
</asp:Label>
</p>
<br />


<asp:GridView ID="xgrid" runat="server" AutoGenerateColumns="False" EnableViewState="true"
DataKeyNames="Col1"
Width="100%" AllowPaging="True" AllowSorting="True">
<Columns>


<asp:TemplateField HeaderText="Col1">
<edititemtemplate>
<asp:TextBox id="dfCodigo" runat="server" Text='<%# Bind("Col1") %>' ></asp:TextBox>
</edititemtemplate>
<itemtemplate>
<asp:Label id="Label2" runat="server" Text='<%# Bind("Col1") %>' ></asp:Label>
</itemtemplate>

</asp:TemplateField>
<asp:TemplateField HeaderText="Nombre" SortExpression="Col2">
<edititemtemplate>
<asp:TextBox runat="server" Text='<%# Bind("Col2") %>' id="TextBox2"></asp:TextBox>
</edititemtemplate>
<itemtemplate>
<asp:Label runat="server" Text='<%# Bind("Col2") %>' id="Label3"></asp:Label>
</itemtemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>

3/4/2008 6:39:37 AM
Gravatar
Total Posts 18439

Re: GridView erroneous behavior on postback

Try adding

Page.EnableViewState = true;

at the beginning of your page load event

By default in mojoPortal content system pages have ViewState disabled to make the page lighter weight (less text rendered) which improves performance. When needed in a module control you can override the default with the line of code I suggested.

If you don't like the default behavior, you can change it in Web.config, look for this:

<add key="DisablePageViewStateByDefault" value="true" />

and set it to false. I recommend leaving it and just use the line of code where needed.

Hope it helps,

Joe

3/4/2008 7:18:34 AM
Gravatar
Total Posts 8

Re: GridView erroneous behavior on postback

 

oooooooppppps Im stupid.

I checked the ViewState status of the gridview, of the control, but never the page viewstate.

 

Thanks Joe

You must sign in to post in the forums. This thread is closed to new posts.