GridView中怎么实现点一个超链接打开一个新窗口,窗口大小自定义?
我用HyperLinkField实现不了,在里加了DataNavigateUrlFormatString= "javascript:window.open ( 'AddTask.aspx?id={0} ', 'newwindow ', 'height=300, width=400,top=200, left=200 ,toolbar=no, menubar=no, scrollbars=no ') "这些,链接就失效了。如果用模板列放HyperLink能实现吗?我要显示的是NAME,传过去的是ID,请问高手怎么实现?
原HyperLinkField代码 <asp:HyperLinkField DataNavigateUrlFields= "TaskID " DataNavigateUrlFormatString= "javascript:window.open ( 'AddTask.aspx ', 'newwindow ', 'height=300, width=400,top=200, left=200 ,toolbar=no, menubar=no, scrollbars=no ') " DataTextField= "TaskSummary " />
------解决方案--------------------function openwindow(url,name,iWidth,iHeight)
{
var url; //转向网页的地址;
var name; //网页名称,可为空;
var iWidth; //弹出窗口的宽度;
var iHeight; //弹出窗口的高度;
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
window.open(url,name, 'height= '+iHeight+ ',,innerHeight= '+iHeight+ ',width= '+iWidth+ ',innerWidth= '+iWidth+ ',top= '+iTop+ ',left= '+iLeft+ ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no ');
}
使用时调用这个函数即可。如:
<a href= "javascript:void(0); " onclick= "javascript:openwindow( 'a.html ', ' ',400,200); "> 转到a </a>
缺点:与原窗口的大小,位置无关,asp.net中Request.UrlRefferer.ToString()无法获取地址。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
关闭子窗口并刷新父页面
Response.Write( " <script> alert( '增加成功. ');opener.location.href=opener.location.href;opener=null;window.close(); </script> ");
------解决方案-------------------- <asp:LinkButton ID= "lbContent " runat= "server " CommandArgument= ' <%# Eval( "MessageID ") %> ' OnCommand= "lbContent_Command " > <%# TruncateString(DataBinder.Eval(Container.DataItem, "SendContent "),60)%> </asp:LinkButton>
protected void lbContent_Command(object sender, CommandEventArgs e)
{
string messageId = e.CommandArgument.ToString();
string sqlupdate = @ "update t_message set fileid =1 where MessageID= " + messageId;
DBUtility.DbHelperSQL.ExecuteSql(sqlupdate);
string script= "openwindows( 'MessageShow.aspx?id= "+messageId+ " ');location.href= 'MessageReceived.aspx ' ";
Page.ClientScript.RegisterStartupScript(this.GetType(), "reload ",script, true);
}
------解决方案--------------------加个 onclick事件 其他的js实现吧