Solved

How do I get my LinkButton to open in a separate window / tab?

Posted on 2014-11-11
12
330 Views
Last Modified: 2014-11-15
I'm having trouble making my LinkButton open in a separate window / tab. How do I do this? In my HTML, its the first LinkButton (ID="lnkbtnGoogleMap")

my HTML

                            <asp:DataGrid ID="dgSummary" runat="server" AllowPaging="True" AllowSorting="true"
                                PagerStyle-Mode="NumericPages" PagerStyle-Position="TopAndBottom" PagerStyle-HorizontalAlign="center"
                                PagerStyle-BackColor="#CCCCCC" PagerStyle-NextPageText="Next Page" PagerStyle-PrevPageText="Prev Page"
                                Font-Size="14px" AutoGenerateColumns="False" CellPadding="2" PageSize="10" Width="80%"
                                OnPageIndexChanged="dgSummary_PageIndexChanged" OnSortCommand="dgSummary_SortCommand"
                                OnItemCommand="dgSummary_ItemCommand">
                                <HeaderStyle BackColor="#CCCCCC" HorizontalAlign="Center" Font-Bold="true"></HeaderStyle>
                                <Columns>
                                    <asp:TemplateColumn Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lblPSEQ" runat="server" Text='<%# Eval("PSEQ") %>' />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lblCompName" runat="server" Text='<%# Eval("PNAME") %>' />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <%--<asp:BoundColumn HeaderStyle-Width="425px" HeaderText="Name" DataField="PNAME" SortExpression="PNAME" />--%>
                                    <asp:TemplateColumn HeaderText="Company Name" ItemStyle-Width="100em" HeaderStyle-ForeColor="#034AF3"
                                        ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkbtnGoogleMap" Text='<%# Eval("PNAME") %>' CommandName="GoogleMap"
                                                runat="server" OnClientClick="_blank"/>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderStyle-Width="400px" HeaderText="City" DataField="PCITY" SortExpression="PCITY"
                                        ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundColumn HeaderStyle-Width="75px" HeaderText="State" DataField="PSTATE" SortExpression="PSTATE"
                                        ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundColumn HeaderStyle-Width="400px" HeaderText="Summary Count" DataField="PCOUNT"
                                        SortExpression="PCOUNT" ItemStyle-HorizontalAlign="Center" />
                                    <asp:TemplateColumn HeaderText="Details" ItemStyle-Width="400px" HeaderStyle-ForeColor="#034AF3"
                                        ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkButton" Text="Show Details" CommandName="ShowDetails" runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                </Columns>
                            </asp:DataGrid>

Open in new window


my C#

protected void dgSummary_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        Label lblCompName;
        Label lblPSEQ;

        lblMsg1.Text = string.Empty;

        if (e.CommandName == "GoogleMap")
        {
            iDB2Connection con;
            iDB2DataReader dbr;
            iDB2Command cmd;

            string strSelect;
            string temp;

            rblDetailsSummary.SelectedIndex = 0;
            lblPSEQ = (Label)e.Item.Cells[0].FindControl("lblPSEQ");
            lblCompName = (Label)e.Item.Cells[0].FindControl("lblCompName");

            using (con = new iDB2Connection())
            {
                con.ConnectionString = ConfigurationManager.AppSettings["ConnString"];
                con.Open();

                strSelect = @"SELECT PADDRESS, PCITY, PSTATE, PZIP FROM ais2000d.POLK WHERE PSEQ = " + lblPSEQ.Text.ToString().Trim();
                cmd = new iDB2Command(strSelect, con);
                dbr = cmd.ExecuteReader();

                if (dbr.Read())
                {
                    if (!dbr["PADDRESS"].ToString().ToUpper().Trim().Equals("ADDRESS NOT AVAILABLE"))
                    {
                        lblMsg1.Text = string.Empty;
                        Response.Redirect("http://maps.google.com/?q=" + dbr["PADDRESS"].ToString().Trim() + "+" +
                            dbr["PCITY"].ToString().Trim() + "+" + dbr["PSTATE"].ToString().Trim() + "+" + dbr["PZIP"].ToString().Trim());
                    }
                    else
                        lblMsg1.Text = @"*** NO ADDRESS AVAILBLE! FOR: " + lblCompName.Text.ToString().Trim() +
                            " IN " + dbr["PCITY"].ToString().Trim() + " ***";
                }
            }
        }
    }

Open in new window

0
Comment
Question by:mikesExpertExchange
  • 9
  • 2
12 Comments
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 40435474
<asp:LinkButton ID="lnkbtnGoogleMap" Text='<%# Eval("PNAME") Target="_blank"%>' CommandName="GoogleMap"
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 40435486
@David: I have that in my LinkButton declaration but it seems to not be working. What am I doing wrong?
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 40435490
@David: No, no I don't, that was a lie! haha lol. Thanks that worked!
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 40435491
@David: I let myself be intimidated by the intellisense not listing: "Target" as an option. When I manually typed it in, as you suggested, it worked fine. Thanks again.
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 40435495
Thanks. If the answer would've been a snake, it would've bit me in the eyeball. Thanks again.
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 40435508
@David: I jumped the gun. Its only opening in a blank window. I need it to go to the google maps address that i'm pointing it behind the scenes in C#. Any suggestions?
0
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 40435568
what is the code (html) that is generated for that?
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 40435621
When I view the source this is what I see. Is this what you're looking for?

<td align="center" style="width:100em;">
                                            <a id="MainContent_dgSummary_lnkbtnGoogleMap_0" Target="_blank" href="javascript:__doPostBack(&#39;ctl00$MainContent$dgSummary$ctl03$lnkbtnGoogleMap&#39;,&#39;&#39;)">AAA COOPER TRANSPORTATION                         </a>
                                        </td><td align="center">STERRETT                           </td><td align="center">AL</td><td align="center">1</td><td align="center" style="width:400px;">
                                            <a id="MainContent_dgSummary_lnkButton_0" href="javascript:__doPostBack(&#39;ctl00$MainContent$dgSummary$ctl03$lnkButton&#39;,&#39;&#39;)">Show Details</a>
                                        </td>

Open in new window

0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 40435623
In Fire Fox, I get a javascript error that reads:

ReferenceError: __doPostBack is not defined
<td align="center" style="width:100em;">
                                            <a id="MainContent_dgSummary_lnkbtnGoogleMap_0" Target="_blank" href="javascript:__doPostBack(&#39;ctl00$MainContent$dgSummary$ctl03$lnkbtnGoogleMap&#39;,&#39;&#39;)">AAA COOPER TRANSPORTATION                         </a>
                                        </td><td align="center">STERRETT                           </td><td align="center">AL</td><td align="center">1</td><td align="center" style="width:400px;">
                                            <a id="MainContent_dgSummary_lnkButton_0" href="javascript:__doPostBack(&#39;ctl00$MainContent$dgSummary$ctl03$lnkButton&#39;,&#39;&#39;)">Show Details</a>
                                        </td>

Open in new window

0
 
LVL 1

Accepted Solution

by:
mikesExpertExchange earned 0 total points
ID: 40436017
I solved it using response #19 from this link:

stackoverflow.com/questions/104601/response-redirect-to-new-window
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 40440966
As it turns out, I did solve it using the link above, as mentioned in my last post. I was having some syntactical issues that I solved and it now seems to be working fine.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question