简体   繁体   English

如何使用gridview(一个新的弹出窗口)中的超链接字段链接回我的主页

[英]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.

相关问题 如何使用新页面作为弹出源创建弹出窗口? - How can I create a pop-up window using a new page as the pop-up source? 如何将文本框的文本从弹出窗口传递到主窗体? - How do I pass the text of a textbox from a pop-up window to the main form? (ASP.NET)如何执行此操作:在GridView中单击按钮以打开包含另一个Gridview的弹出窗口 - (ASP.NET) How to do this: Button click in GridView to open pop-up window containing another Gridview 重定向到新选项卡中的页面时,请避免使用弹出窗口阻止程序 - Avoid Pop-up blocker when redirecting to a page in a new tab 如何在GridView中打开一个链接的弹出窗口 - how to open a pop up window to a link in gridview 如何在代码隐藏文件中设置超链接列gridview的格式? - How do I format hyperlink column gridview in my codebehind file? 如何在WPF中从弹出对话框窗口导航到另一个页面我未使用MVVM - How to navigate from a pop-up dialog window to another page in wpf i'm not using MVVM 单击弹出窗口中的按钮后,如何刷新上一页? - How to make previous page refresh after I click a button in pop-up window? 如何通过ASP.NET显示弹出对话框并获取弹出窗口的值 - How to show a pop-up dialog through ASP.NET and get the value of the pop up back 如何在 C# WinForms 中执行类似 explorer.exe 的弹出窗口? - How can I do a pop-up like explorer.exe in C# WinForms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM