[英]javascript - window.open
How can I concatenate ID from database and URL? 如何从数据库和URL连接ID?
This is my code. 这是我的代码。 I have an error "The server tag is not well formed."
我收到一个错误“服务器标签格式不正确”。
NavigateUrl="javascript:void(window.open('ChangeHistory.aspx?ID="<%# DataBinder.Eval(Container.DataItem, "id")%>" ','_blank','height=600','width=600') );"
I think this is what you need: 我认为这是您需要的:
NavigateUrl="javascript:void(window.open('ChangeHistory.aspx?ID=<%# DataBinder.Eval(Container.DataItem, "id")%>','_blank','height=600','width=600') );"
That is, remove the "
that was just before <%
and the one from just after >%
. 也就是说,删除
"
这仅仅是前<%
和从刚过一个>%
You should try adding the NavigateUrl
Attribute from server side code...it will be very easy and also to include your ID
in window.open
method. 您应该尝试从服务器端代码添加
NavigateUrl
属性...这将非常容易,并且还将您的ID
包含在window.open
方法中。
if it's in some Grid/Repeater/Datalist
then use the DataBound
property otherwise use Page_Load
event to add attribute to it... 如果它在某些
Grid/Repeater/Datalist
则使用DataBound
属性,否则使用Page_Load
事件向其添加属性...
Example 例
Foocontrol.NavigateUrl=@"javascript:void(window.open
('ChangeHistory.aspx? ID='"+YourID+"','_blank','height=600','width=600') )";
Edit 编辑
protected void yourGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink hlnkViewHistory = (HyperLink)e.Row.FindControl("hlnkViewHistory");
hlnkViewHistory.NavigateUrl==@"javascript:void(window.open
('ChangeHistory.aspx? ID='"+YourID+"','_blank','height=600','width=600') )";
}
}
YourID - add your ID whatever you want to send as parameter.... YourID-添加您要发送的ID作为参数。
Try this. 尝试这个。 I have changed this
我已经改变了
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# String.Format("ChangeHistory.aspx?id={0}", Eval("id")) %>' onclick="javascript:w= window.open(this.href,'DownloadImage','left=20,top=20,width=500,height=500,toolbar=0,resizable=0');return false;">Open</asp:HyperLink>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.