日期:2014-05-17  浏览次数:20611 次

Page.ClientScript.RegisterStartupScript如何向后台传递参数
我在前台写了一段代码:
 public void bt1_Click(object sender, EventArgs e)
  {
  string roomname = Request["room_name"];
   
  Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language='javascript'>window.showModalDialog('switch.aspx?RoomName='"+roomname+"'','','dialogHeight:200px;dialogWidth:220px;edge: Raised;center:no;help: no; resizable: off; status: no;unadorned:no;scroll:no;resizable:no;help:no');<" + "/script>");

  }
后台接收参数的代码:
protected void Page_Load(object sender, EventArgs e)
{
  string roomname = Request.QueryString["RoomName"];
  Response.Write(roomname)

}
问题是为什么接收不到RoomName参数呢?小女子不才,请大家帮帮忙!我已经想的头的大了。

------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
{
string roomname = Request.QueryString["RoomName"];
Response.Write(roomname)

}这代码写在swith.aspx.cs页面吗
------解决方案--------------------
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "window.showModalDialog('switch.aspx?RoomName="+roomname+"','','dialogHeight:200px;dialogWidth:220px;edge: Raised;center:no;help: no; resizable: off; status: no;unadorned:no;scroll:no;resizable:no;help:no');",true);

你的?是中文的,必须是英文的才行
------解决方案--------------------
最好进行下编码
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "window.showModalDialog('switch.aspx?RoomName="+ Server.UrlEncode(roomname) + "','','dialogHeight:200px;dialogWidth:220px;edge: Raised;center:no;help: no; resizable: off; status: no;unadorned:no;scroll:no;resizable:no;help:no');",true);