This is a migrated thread and some comments may be shown as answers.

How to set up new opened IExplorer window called from RadGrid Hyperlink column

2 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Willy Vidable
Top achievements
Rank 1
Willy Vidable asked on 01 Jun 2010, 05:47 PM
Hi,

I have a RadGrid with an Hyperlink column that when clicked opens a new IExplorer window that shows a web page with information related to the row.

I want to control what the new opened IExplorer window shows. Like hide the menu bar, status bar, enable/disable resizing and the like.

I understand that the way to go is using javascript function window.open(). Now since I am using the RadGrid Hyperlink column with the property "Target= _blank",  my question is:

Where I suppoese  to inser the javascript string to call the new window set up as I want it?
or
Is there any other method or best practice to accomplish this in the context of Telerik RadGrid component?

Any advice would be appreciated.

2 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 04 Jun 2010, 11:23 AM
Hi Willy,

The GridHyperLinkColumn renders regular HTML anchor elements in the column cells. This means that you are getting some link of the form:

<a href="http://www.google.com" target="_blank">Open Google</a>

To customize how the new window opens, you can modify this hyperlink to:

<a href="http://www.google.com" target="_blank"
    onclick="window.open(this.href);return false;">Open Google</a>

Now you can use window.open() to pass arguments that will resize the new browser window and toggle its features. You can apply this onclick event handler to your hyperlink columns using RadGrid's ItemDataBound event. Syppose your hyperlink column's UniqueName is "HyperlinkColumn".  Then you would have:

protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        HyperLink link = (HyperLink)item["HyperlinkColumn"].Controls[0];
        link.Attributes["onclick"] = "window.open(this.href);return false;";
    }
}

Now you can customize how the window opens from inside the hyperlink column. Make sure you include the last return false statement in the click handler. Otherwise you will get your window opened twice - once for window.open() and once as a result of the default link click behavior.

Regards,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Willy Vidable
Top achievements
Rank 1
answered on 04 Jun 2010, 06:47 PM
HI Veli,

Thanks a lot for your answer. That was what I was looking for. It works perfect.

Just for the sake of clarification, in case that somebody else may face the same issue let me paste how my code looks like.

Note
: My application has a RadGrid with an Hyperlink column called "Print" that open a new IExplorer instance showing a printable version of the current row in the RdGrid using a Telerik Reporting object. My intentions was to control how the new opened window looks. In this case just hide the toolbar.

protected void rgLoadTickets_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
             
            GridDataItem item = (GridDataItem)e.Item;  
            HyperLink link = (HyperLink)item["Print"].Controls[0];  
            link.Attributes["onclick"] = "window.open(this.href,'MyWindowName','toolbar=No');return false;";  
        }  
    } 


Regards

 

 

Tags
Grid
Asked by
Willy Vidable
Top achievements
Rank 1
Answers by
Veli
Telerik team
Willy Vidable
Top achievements
Rank 1
Share this question
or