Can't use "Request.QueryString[]" in MojoPortal.

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.
4/23/2010 10:41:26 PM
Gravatar
Total Posts 2

Can't use "Request.QueryString[]" in MojoPortal.

Hi,

I use the"Request.QueryString[]" in my control which is belonged to "acme.web.UI", but it can't work.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Globalization;
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 mojoPortal.Web;
using mojoPortal.Web.Framework;
using mojoPortal.Web.UI;
//using log4net;
//using acme.Features.Business;
using Resources;
using acme.Business;
using mojoPortal.Data;
using System.Text;
using Npgsql;

namespace acme.Web.UI
{
public partial class GeDiYouXun : SiteModuleControl
{
#region
/// <summary>
/// 用于保存从表lt_multiplacetourinfo中提取的数据
/// </summary>
private DataTable dt_multiplacetourinfo_one = null;

#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindData();
}

//绑定数据
private void BindData()
{
try
{
int iID = Convert.ToInt32(Request.QueryString["MyID"].ToString());
lblTitle.Text = dt_multiplacetourinfo_one.Rows[0]["TourTitle"].ToString();

}
catch(Exception ex)
{
Response.Write("<script>alert('" + ex.Message "')</script>");
}
}
}
}

4/24/2010 9:01:56 AM
Gravatar
Total Posts 18439

Re: Can't use "Request.QueryString[]" in MojoPortal.

Hi,

There are a number of problems with your code.

The biggest problem is you are trying to use Response.Write in an error handler and this also throws an error. You should not use Response.Write from code behind except under special circumstances, this is not classic ASP. You need to understand the page rendering model where controls are built into a control tree and then rendered recursively. You break the control tree with this Response.Write. You could put a Label control on the page and then set the .Text property of the label to show your error.

Instead of wrapping a try catch around:

int iID = Convert.ToInt32(Request.QueryString["MyID"].ToString());

you should check for the existence of the query string param first, we have a helper method that can do it for you, you pass in a default value in case the param is not there.

int foo =  WebUtils.ParseInt32FromQueryString("foo", -1);

also the line

lblTitle.Text = dt_multiplacetourinfo_one.Rows[0]["TourTitle"].ToString();

will throw an error because dt_multiplacetourinfo_one is null

Hope it helps,

Joe

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