当前位置: 代码迷 >> ASP.NET >> Page.ClientScript.RegisterStartupScript怎么向后台传递参数
  详细解决方案

Page.ClientScript.RegisterStartupScript怎么向后台传递参数

热度:4938   发布时间:2013-02-25 00:00:00.0
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);
  相关解决方案