一个简单的window.open 就是提示语法错误,帮忙看下。

yumanqing 2009-01-16 02:54:36

int rIndex = GridView1.SelectedIndex;
Label lbl = (Label)GridView1.Rows[rIndex].FindControl("lblpCode");
string pCode = lbl.Text;
ClientScriptManager cs = Page.ClientScript;
string script = "<script> window.open('UserDetails.aspx?pCode="+pCode+"','_blank','width=780,height=550');</script>";
cs.RegisterStartupScript(this.GetType(), "", script, true);

===问题==
总是提示JS语法错误,不知道是那里语法错误,对这个不是很熟悉,谢谢
...全文
171 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
yumanqing 2009-01-17
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 zerostyle 的回复:]
int rIndex = GridView1.SelectedIndex;
Label lbl = (Label)GridView1.Rows[rIndex].FindControl("lblpCode");
string pCode = lbl.Text;
ClientScriptManager cs = Page.ClientScript;
string script = " <script> window.open('UserDetails.aspx?pCode="+pCode+"','_blank','width=780,height=550'); </script>";
cs.RegisterStartupScript(this.GetType(), "", script, t…
[/Quote]

那怎么能取到没次单击行的数据的值呢?不好意思,对ASP.NET不熟悉
zerostyle 2009-01-16
  • 打赏
  • 举报
回复
int rIndex = GridView1.SelectedIndex;
Label lbl = (Label)GridView1.Rows[rIndex].FindControl("lblpCode");
string pCode = lbl.Text;
ClientScriptManager cs = Page.ClientScript;
string script = " <script> window.open('UserDetails.aspx?pCode="+pCode+"','_blank','width=780,height=550'); </script>";
cs.RegisterStartupScript(this.GetType(), "", script, true);


你的单击已经导致回发,你的脚本还能打开新窗口?它只会再次被注册!
你为什么不在行绑定的时候来注册脚本?
你该改成在_RowDataBound事件中:
yumanqing 2009-01-16
  • 打赏
  • 举报
回复
up,在线等...
BossFriday 2009-01-16
  • 打赏
  • 举报
回复
pCode里是否有非法字符呢?你得让大家看看js的错误信息.
感觉是个很简单的问题.
真不知道,你得一颗星是怎么来的.
koukoujiayi 2009-01-16
  • 打赏
  • 举报
回复
对了,还有上面这段代码写在GridView的模板列的单击事件中,可是SelectedIndex一直都不变化,为什么?
====================================================================================
单击的按钮的CommandName属性设置了Select了吗?
yumanqing 2009-01-16
  • 打赏
  • 举报
回复
Quote=引用 9 楼 Fly_free_ 的回复:]
cs.RegisterStartupScript(this.GetType(), "", script, true);
里的true是默认在你的script上加上 <script> </script>所以要去掉;
[/Quote]
这个问题已经解决,
int rIndex = GridView1.SelectedIndex; 
Label lbl = (Label)GridView1.Rows[rIndex].FindControl("lblpCode");
string pCode = lbl.Text;
ClientScriptManager cs = Page.ClientScript;
string script = " <script> window.open('UserDetails.aspx?pCode="+pCode+"','_blank','width=780,height=550'); </script>";
cs.RegisterStartupScript(this.GetType(), "", script, true);

这段代码写在GridView的模板列的单击事件中,可是SelectedIndex一直都不变化,为什么?
Fly_free_ 2009-01-16
  • 打赏
  • 举报
回复
cs.RegisterStartupScript(this.GetType(), "", script, true);
里的true是默认在你的script上加上<script></script>所以要去掉;
yumanqing 2009-01-16
  • 打赏
  • 举报
回复
对了,还有上面这段代码写在GridView的模板列的单击事件中,可是SelectedIndex一直都不变化,为什么?
int rIndex = GridView1.SelectedIndex;
Label lbl = (Label)GridView1.Rows[rIndex].FindControl("lblpCode");
string pCode = lbl.Text;
ClientScriptManager cs = Page.ClientScript;
string script = "<script> window.open('UserDetails.aspx?pCode="+pCode+"','_blank','width=780,height=550');</script>";
cs.RegisterStartupScript(this.GetType(), "", script, true);

z3315083 2009-01-16
  • 打赏
  • 举报
回复
运行之后.看生成的页面里的js..就懂得是哪错了.
要学会找错误的办法~~
llsen 2009-01-16
  • 打赏
  • 举报
回复
[Quote=引用楼主 yumanqing 的帖子:]
C# code
int rIndex = GridView1.SelectedIndex;
Label lbl = (Label)GridView1.Rows[rIndex].FindControl("lblpCode");
string pCode = lbl.Text;
ClientScriptManager cs = Page.ClientScript;
string script = "<script> window.open('UserDetails.aspx?pCode="+pCode+"','_blank','width=780,height=550');</script>";
cs.RegisterStartupScript(this.GetType(), "", scri…
[/Quote]


去掉红色部分
koukoujiayi 2009-01-16
  • 打赏
  • 举报
回复
string script = "<script language=javascript>window.open('UserDetails.aspx.aspx?pCode=" + pCode + "','','width=780,height=550');</script>";
koukoujiayi 2009-01-16
  • 打赏
  • 举报
回复
_blank也应该去掉!!
string script = "<script>window.open('UserDetails.aspx?pCode=" + pCode + "','','width=780,height=550');</script>";
Teng_s2000 2009-01-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 koukoujiayi 的回复:]
cs.RegisterStartupScript(this.GetType(), "", script, true);
把true去掉!!
[/Quote]
ls说的就不抱错了,不过我的IE7还是弹不出
koukoujiayi 2009-01-16
  • 打赏
  • 举报
回复
cs.RegisterStartupScript(this.GetType(), "", script, true);
把true去掉!!
dreamzyl 2009-01-16
  • 打赏
  • 举报
回复
把script里面的<script>标记去掉就可以了

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧