After I add a new item on the Administrator Menu,when I open the new page,the page is blank?

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.
6/1/2009 4:12:41 AM
Gravatar
Total Posts 16

After I add a new item on the Administrator Menu,when I open the new page,the page is blank?

   I create a new module like ConsignForm.ascx for submitting users' information. And this control's function is ok. When a user fill some information,then click the submit button, the information insert to the database's table as mp_ConsignForm.

    Now, I want to create the ConsignFormAdmin.aspx for Admin to manage the mp_ConsignForm table's information like select, update,delete...
The following is my steps:
1: open the Admin/AdminMenu.aspx, then add the ConsignForm HyperLink as  

 <li id="liConsignForm" runat="server">
<asp:HyperLink ID="lnkConsign" runat="server" />
</li>
 

then go to AdminMenu.aspx.cs, add

 lnkConsign.Text = "ConsignForm";
lnkConsign.NavigateUrl = SiteRoot + "/Admin/ConsignFormAdmin.aspx";

2: So on the Administrator Menu, appear ConsignForm label.
3: I create ConsignFormAdmin.aspx on the Admin folder, I use the GridView to select the data.The code as follows;

<%@ Page Language="C#" AutoEventWireup="false" MasterPageFile="~/App_MasterPages/layout.Master" CodeBehind="ConsignFormAdmin.aspx.cs" Inherits="mojoPortal.Web.AdminUI.ConsignFormAdmin" %>

<asp:Content ContentPlaceHolderID="leftContent" ID="MPLeftPane" runat="server" >
</asp:Content>
<asp:Content ContentPlaceHolderID="mainContent" ID="MPContent" runat="server">
<mp:CornerRounderTop id="ctop1" runat="server" />
<asp:Panel ID="pnlConsignForm" runat="server" CssClass="panelwrapper admin admintaxrate">
<div>

<mp:mojoGridView ID="GrdConsignFrom" runat="server" AllowPaging="True"
AutoGenerateColumns="False" PageSize="12"
OnRowCancelingEdit="GrdConsignFrom_RowCancelingEdit" OnRowEditing="GrdConsignFrom_RowEditing"
OnRowUpdating="GrdConsignFrom_RowUpdating" OnRowDeleting="GrdConsignFrom_RowDeleting"
OnPageIndexChanging="GrdConsignFrom_PageIndexChanging"
BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
CellPadding="4" CellSpacing="2" ForeColor="Black"
DataKeyNames="Id"

>

<Columns>
<asp:BoundField DataField="weituolx" HeaderText="委托类型"
/>
<asp:BoundField DataField="fangwulx" HeaderText="房屋类型"
/>
<asp:BoundField DataField="fangyuanqy" HeaderText="房源区域"
/>
<asp:BoundField DataField="huxing" HeaderText="户型"
/>

<asp:BoundField DataField="fangyuandd" HeaderText="房源地段"
/>
<asp:BoundField DataField="jianzhumj" HeaderText="建筑面积"
/>
<asp:BoundField DataField="nidingjg" HeaderText="拟定价格"
/>
<asp:BoundField DataField="changquangs" HeaderText="产权归属"
/>
<asp:BoundField DataField="jianzhund" HeaderText="建筑年代"
/>
<asp:BoundField DataField="fangwuzhx" HeaderText="房屋装修"
/>
<asp:BoundField DataField="jiaotongzhk" HeaderText="交通状况"
/>
<asp:BoundField DataField="buchongshm" HeaderText="补充说明"
/>
<asp:BoundField DataField="lianxir" HeaderText="联系人"
/>
<asp:BoundField DataField="dianhua" HeaderText="电话"
/>
<asp:BoundField DataField="chuanzhen" HeaderText="传真"
/>
<asp:BoundField DataField="Time_log" HeaderText="最新时间"
SortExpression="Time_log" />

<asp:CommandField HeaderText="编辑" ShowEditButton="True" />

</Columns>
<FooterStyle BackColor="#CCCCCC" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
</mp:mojoGridView>
<br />
<%-- <asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Mojo_tianzhuju_sourcecodeConnectionString %>"
SelectCommand="SELECT * FROM [mp_ConsignForm]"></asp:SqlDataSource>
--%></div>

</asp:Panel>
<mp:CornerRounderBottom ID="cbottom1" runat="server" />

</asp:Content>
<asp:Content ContentPlaceHolderID="rightContent" ID="MPRightPane"
runat="server" >
</asp:Content>
<asp:Content ContentPlaceHolderID="pageEditContent" ID="MPPageEdit" runat="server" />
 

Then I find this error: the page is blank, the page does't show the table's information. So how do you think? some error in this CosignForm.aspx page or on the ConsignForm.aspx.cs code?

thank you very much.

6/1/2009 4:18:43 AM
Gravatar
Total Posts 16

Re: After I add a new item on the Administrator Menu,when I open the new page,the page is blank?

the ConsignFormAdmin.aspx.cs code as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Globalization;
using mojoPortal.Web.Framework;
using mojoPortal.Business;
using mojoPortal.Business.WebHelpers;

namespace mojoPortal.Web.AdminUI
{
public partial class ConsignFormAdmin : mojoBasePage
{
protected void Page_Load(object sender, EventArgs e)
{
//if (Session["UserName"] == null)
//{
// Response.Redirect("../Secure/Login.aspx");
//}
if (!IsPostBack)
{

GridViewBind();
}

}

protected void GrdConsignFrom_PageIndexChanging (object sender, GridViewPageEventArgs e)
{
//GridView GrdConsignFrom = (GridView)sender;
GrdConsignFrom.PageIndex = e.NewPageIndex;

GridViewBind();
}

private void GridViewBind()
{

string strconn = "server=.;database=Mojo_Tianzhuju;uid=sa;pwd=p@ssw0rd";
SqlConnection Conn = new SqlConnection(strconn);
Conn.Open();

//GridView GrdConsignFrom = (GridView)sender;

string SqlStr = "SELECT Id,weituolx,fangwulx,fangyuanqy,huxing,fangyuandd,jianzhumj,nidingjg,changquangs,jianzhund,fangwuzhx,jiaotongzhk,buchongshm,lianxir,dianhua,chuanzhen,Time_log FROM [mp_ConsignForm]";
SqlDataAdapter sda = new SqlDataAdapter(SqlStr, strconn);
DataSet ds = new DataSet();

try
{
SqlConnection conn = new SqlConnection(strconn);
if (conn.State.ToString() == "Closed") conn.Open();
SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
da.Fill(ds, "mp_ConsignForm");
if (conn.State.ToString() == "Open") conn.Close();


GrdConsignFrom.DataSource = ds.Tables[0].DefaultView;
GrdConsignFrom.DataBind();
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
Response.End();
}
}

 

 


protected void GrdConsignFrom_RowEditing(object sender, GridViewEditEventArgs e)
{
//GridView GrdConsignFrom = (GridView)sender;
GrdConsignFrom.EditIndex = e.NewEditIndex;

GridViewBind();
}

protected void GrdConsignFrom_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//GridView GrdConsignFrom = (GridView)sender;
GrdConsignFrom.EditIndex = -1;
GridViewBind();
}
protected void GrdConsignFrom_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string strconn = "server=.;database=Mojo_tianzhuju_sourcecode;uid=sa;pwd=p@ssw0rd";
SqlConnection Conn = new SqlConnection(strconn);
Conn.Open();
//GridView GrdConsignFrom = (GridView)sender;
string id = GrdConsignFrom.DataKeys[e.RowIndex].Values[0].ToString();

string ddlConsignType = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[0].Controls[0])).Text.Trim();
string rbthouse = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[1].Controls[0])).Text.Trim();
string ddlavaireg = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[2].Controls[0])).Text.Trim();
string strhuxing = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[3].Controls[0])).Text.Trim();

string stravalot = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[4].Controls[0])).Text.Trim();
string strconarea = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[5].Controls[0])).Text.Trim();
string strpreprice = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[6].Controls[0])).Text.Trim();
string strproowner = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[7].Controls[0])).Text.Trim();
string strbuilding = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[8].Controls[0])).Text.Trim();
string strhousren = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[9].Controls[0])).Text.Trim();
string strtracondition = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[10].Controls[0])).Text.Trim();
string strsupinfor = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[11].Controls[0])).Text.Trim();
string strcontact = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[12].Controls[0])).Text.Trim();
string strtel = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[13].Controls[0])).Text.Trim();
string strfax = ((TextBox)(GrdConsignFrom.Rows[e.RowIndex].Cells[14].Controls[0])).Text.Trim();
string strdate = DateTime.Now.ToString();


//string connStr = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
string SqlStr = "update mp_ConsignForm set weituolx=N'" + ddlConsignType + "',fangwulx=N'" + rbthouse + "',fangyuanqy=N'" + ddlavaireg + "',huxing=N'" + strhuxing + "',fangyuandd=N'" + stravalot + "',jianzhumj=N'" + strconarea + "',nidingjg=N'" + strpreprice + "',";
SqlStr += "changquangs=N'" + strproowner + "',jianzhund=N'" + strbuilding + "',fangwuzhx=N'" + strhousren + "',jiaotongzhk=N'" + strtracondition + "',buchongshm=N'" + strsupinfor + "',lianxir=N'" + strcontact + "',dianhua=N'" + strtel + "',chuanzhen=N'" + strfax + "',Time_log='" + strdate + "'where id=" + id;

try
{
string strconn1 = "server=.;database=Mojo_tianzhuju_sourcecode;uid=sa;pwd=p@ssw0rd";
SqlConnection conn = new SqlConnection(strconn1);
if (conn.State.ToString() == "Closed") conn.Open();
SqlCommand comm = new SqlCommand(SqlStr, conn);
comm.ExecuteNonQuery();
comm.Dispose();
if (conn.State.ToString() == "Open") conn.Close();

GrdConsignFrom.EditIndex = -1;
GridViewBind();
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
Response.End();
}
}
protected void GrdConsignFrom_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//GridView GrdConsignFrom = (GridView)sender;
string id = GrdConsignFrom.DataKeys[e.RowIndex].Values[0].ToString();
string connStr = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
string SqlStr = "delete from mp_ConsignForm where id=" + id;

try
{
SqlConnection conn = new SqlConnection(connStr);
if (conn.State.ToString() == "Closed") conn.Open();
SqlCommand comm = new SqlCommand(SqlStr, conn);
comm.ExecuteNonQuery();
comm.Dispose();
if (conn.State.ToString() == "Open") conn.Close();

GrdConsignFrom.EditIndex = -1;
GridViewBind();
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
Response.End();
}
}

 

 


}
}
 

When I set breakpoints on the cs code, it has no response. So I think something wrong of the Gridview, I have changed the <asp:GridView to <mp:mojoGridView . But it no use, can you help me check this?

thanks

6/1/2009 5:59:18 AM
Gravatar
Total Posts 18439

Re: After I add a new item on the Administrator Menu,when I open the new page,the page is blank?

Hi,

First I would suggest don't modify mojoportal code like in AdminMenu.aspx. If you do that how will you be able to upgrade?

What I would do is make and edit page and link it into the module title just like any other feature, so the edit/manage link shows up to users with edit permissions.

If you really want a link in the admin menu there is a way to do it with a config file so you don't have to touch the code there.

http://www.mojoportal.com/addingcustomitemstotheadministrationmenu.aspx

I think the biggest problem with your code is that you are using Response.Write in your error handler and that interupts the page lifecycle of control rendering and borks the output.

I think you get an error right away when it data binds and then it hoses the output with response.write.

While developing you should not use try catch, just let it throw the error and then you will know what the problem is.

Later if there is an expected error that may occur you can catch that specific error instead of swallowing all Exceptions.

To log errors you should use log4net and log to the mojoportal error log.

using log4net;

private static readonly ILog log = LogManager.GetLogger(typeof(ConsignFormAdmin));

catch
{
log.Error(ex);
}

Hope it helps,

Joe

6/1/2009 10:24:42 PM
Gravatar
Total Posts 16

Re: After I add a new item on the Administrator Menu,when I open the new page,the page is blank?

I find the problem. I miss some code on the Page_Load function.

Thank you the same.

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