[英]How do I use the hyperlink field in gridview, a new pop-up, to link back to my main page
I have created a page with a button that opens up a new page, a pop-up if you will. 我创建了一个带有按钮的页面,该按钮可以打开一个新页面,如果可以的话,会弹出一个页面。
btnToolbarSearch.Attributes.Add("onclick", "window.open('DagbokSearch.aspx','','height=600,width=600');return false");
On this new page that opens up I have a gridview where you get the below info. 在打开的这个新页面上,我有一个gridview,您可以在其中获取以下信息。 (You do a search on the "from date" to the "to date" and get the records in between.)
(您可以在“从日期”到“到日期”之间进行搜索,并获得介于两者之间的记录。)
The first column where it says "Gå till" is a link 标题为“直到”的第一列是一个链接
<asp:HyperLinkField DataNavigateUrlFields="Foretag"
DataNavigateUrlFormatString="userProfile.aspx?ID={0}"
Text="Gå till" />
I would like this link to get me back to the previous page and open up the object with the corresponding id, I'm not sure how to accomplish this. 我希望通过此链接回到上一页并打开具有相应ID的对象,但我不确定如何完成此操作。 Maybe there is a better way then the one I'm using but I'm still learning.
也许有比我正在使用的方法更好的方法,但我仍在学习。
You can set its NavigateUrl property in the Rowdatabound event of the gridview. 您可以在gridview的Rowdatabound事件中设置其NavigateUrl属性。 Like;
喜欢;
protected void gvDogBok_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((HyperLink)e.Row.Controls[1].Controls[1]).NavigateUrl = "~/userProfile.aspx?ID="+((YourType)e.Row.DataItem).ID+"";
}
}
I'm not sure if what you are asking can be done. 我不确定您的要求是否可以解决。 I would advice you to use a floating div popup instead.
我建议您改用浮动div弹出窗口。 This way you dont have to leave the current page and go to a new tab.
这样,您不必离开当前页面并转到新选项卡。 This should solve your problem and does avoid problems with popup blockers.
这样可以解决您的问题,并且可以避免弹出窗口阻止程序出现问题。
Here are some examples: http://www.javascripttoolbox.com/lib/popup/example.php 以下是一些示例: http : //www.javascripttoolbox.com/lib/popup/example.php
Use this one 用这个
protected void gvDogBok_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((HyperLink)e.Row.Controls[1].Controls[1]).Attribute.Add("onclick", "window.opener.location =userProfile.aspx?ID="+ ((YourType)e.Row.DataItem).ID+"; window.close();";
}
}
You can set JavaScript:window.location.replace(url); 您可以设置JavaScript:window.location.replace(url); to the clientside onclick of the HyperLink.
到HyperLink的客户端onclick。 window.location.replace(url) will reload the page.
window.location.replace(url)将重新加载页面。
btnToolbarSearch.Attributes.Add("onclick", "var windowHandle = window.open('DagbokSearch.aspx','','height=600,width=600');return false");
and on hyperlink cleint side onclick 在超链接cleint侧onclick
hyperLink.Attributes.Add("onclick", "windowHandle.close();window.location.replace(url);return false");
You should be able to use the window.opener
property to get a reference to the parent window. 您应该能够使用
window.opener
属性来获取对父窗口的引用。 You can then set it's URL to the selected link, and close the popup window. 然后可以将其URL设置为选定的链接,然后关闭弹出窗口。
Something like this should do the trick: 这样的事情应该可以解决问题:
// Place this near your closing </body> tag
// NB Uses jQuery and event delegation
$(function() {
$('table').on('click', 'tr > td:first > a', function(event) {
if (window.opener) {
event.preventDefault();
window.opener.location.href = this.href;
window.close();
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.