参数传递出现空格,该如何处理
参数传递出现空格
接收页运行时地址:http://localhost:1366/anshengjielun.aspx?tid%20=%2020141
我想请问各位老师%20这个空格错误如何解决。
发送页代码:
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("anshengjielun.aspx?tid = " + TextBox1.Text.Trim());
}
接收页代码
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{
if (Request.QueryString["id"]!= null)
{
int bid = int.Parse(Request.QueryString["tid"].ToString().Trim());
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
SqlCommand cmd = new SqlCommand("select AJID,AJTIME,NSRSBH,NM,AJSQ,TQR from ERkelingdao where AJID = " + bid, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
this.TextBox1.Text = Convert.ToString(dr["AJID"]);
this.TextBox11.Text = Convert.ToString(dr["AJTIME"]);
this.TextBox3.Text = Convert.ToString(dr["NSRSBH"]);
this.TextBox4.Text = Convert.ToString(dr["NM"]);
this.TextBox5.Text = Convert.ToString(dr["AJSQ"]);
this.TextBox6.Text = Convert.ToString(dr["TQR"]);
}
}
}
}
}
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
tid 后台有空格,接收的时候也是会有空格的,传递参数的时候要注意这一点。
接收页运行时地址:http://localhost:1366/anshengjielun.aspx?tid%20=%2020141
我想请问各位老师%20这个空格错误如何解决。
发送页代码:
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("anshengjielun.aspx?tid = " + TextBox1.Text.Trim());
}
接收页代码
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{
if (Request.QueryString["id"]!= null)
{
int bid = int.Parse(Request.QueryString["tid"].ToString().Trim());
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
SqlCommand cmd = new SqlCommand("select AJID,AJTIME,NSRSBH,NM,AJSQ,TQR from ERkelingdao where AJID = " + bid, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
this.TextBox1.Text = Convert.ToString(dr["AJID"]);
this.TextBox11.Text = Convert.ToString(dr["AJTIME"]);
this.TextBox3.Text = Convert.ToString(dr["NSRSBH"]);
this.TextBox4.Text = Convert.ToString(dr["NM"]);
this.TextBox5.Text = Convert.ToString(dr["AJSQ"]);
this.TextBox6.Text = Convert.ToString(dr["TQR"]);
}
}
}
}
}
------解决方案--------------------
Response.Redirect("anshengjielun.aspx?tid = " + TextBox1.Text.Trim()); //等号前后有空格啊,去掉不就好了么
------解决方案--------------------
Response.Redirect("anshengjielun.aspx?tid =这个地方有空格的话,你接收的时候石油空格的。 " + TextBox1.Text.Trim());
------解决方案--------------------
tid 后台有空格,接收的时候也是会有空格的,传递参数的时候要注意这一点。