Solved

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

Posted on 2014-11-11
12
307 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 78

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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 78

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now