Solved

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

Posted on 2014-11-11
12
312 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

17 Experts available now in Live!

Get 1:1 Help Now