Solved

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

Posted on 2014-11-11
12
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 2
12 Comments
 
LVL 81

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 81

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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