Solved

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

Posted on 2014-11-11
12
321 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 79

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 79

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mail.To.Add 5 25
Error handling in asp.net site 5 25
start a process from a service 3 21
Please explain the parts of these 2 LINQ expressions 3 27
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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