参数传递出问题,一个字出错?两个字就可以了
新手刚学ASP.Net,高手求救!
这是打开新页面的语句:
Response.Write( " <script> window.open( 'ShowScanNews.aspx?Scankey= "+newskey.Text.Trim()+ "&type= "+scantype.SelectedValue.Trim()+ " ') </script> ");
在打开的新页面中,用下面语句获得参数值:
String sScankey = Request.QueryString[ "Scankey "].ToString();
String sScantype = Request.QueryString[ "type "].ToString();
scantype为下拉控件,两个值分别为 "新闻标题 "和 "新闻内容 ",newskey为TextBox控件,当设值为两个个字如 "新闻 ",调试正常,其中sScankey= "新闻 " sScantype= "新闻标题 ";但当Textbox中输入一个字 "闻 "时,调试出错,其中sScankey= "?type=新闻标题 ",然后出错!
到底出了什么问题?
[解决办法]
这是打开新页面的语句:
Response.Write( " <script> window.open( 'ShowScanNews.aspx?Scankey= "+
Server.UrlEncode(newskey.Text.Trim())+ "&type= "+
Server.UrlEncode(scantype.SelectedValue.Trim())+ " ') </script> ");
在打开的新页面中,用下面语句获得参数值:
String sScankey =Server.UrlDecode(Request.QueryString[ "Scankey "]);
String sScantype =Server.UrlDecode(Request.QueryString[ "type "]);