u welcome friend .. yeah i know that ur Linkbutton inside a Gridview ... that also works .. go to ASPX Page and Put the Script and Call it at ur Gridview's linkbutton event "onclientclick " as i explaned above .
thanks .. but my link buttons r within gridview .. im binding my GV on run time pls go through my code..
The reason you might not think the posted solution will work is because link buttons are "smoke and mirrors". It's not a "normal" link. When your page is rendered, the link simply calls javascript when clicked, and that javascript submits the form. Making
the form submit to a new window will solve your issue. However you might have a problem if other controls on the page also submit (buttons etc) but you don't want those to open in a new window.
narasappa
Participant
960 Points
458 Posts
opening page in New Window
Apr 30, 2012 11:47 AM|LINK
hi all
i have a Link Buttons in GridView after clicking LB i need open Page in New Window i used
protected void ViewInvoice(object sender, CommandEventArgs e) { int count=GvInvoice.Rows.Count; GridViewRow row = GvInvoice.Rows[1]; Label in_id=row.Cells[1].FindControl("lblInvoice") as Label; if(in_id!=null) { string invid=in_id.Text; string URL_Invoice= "~/Invoices/"+invid+".pdf?in_id={0}"; Response.Redirect(string.Format(URL_Invoice, e.CommandArgument.ToString())); } }ravi.jadiyannavar@gmail.com
Pls Mark This Post As Answer If it Helps U..
Thanku
Eng-Mondy
Member
189 Points
71 Posts
Re: opening page in New Window
Apr 30, 2012 12:11 PM|LINK
put the Script above of ur page .. and then call its Function into ur Button or linkButton into the 'onclientclick '.. etc example
<script type="text/javascript"> function PostToNewWindow() { originalTarget = document.forms[0].target; document.forms[0].target='_blank'; window.setTimeout("document.forms[0].target=originalTarget;",300); return true; } </script> <asp:LinkButton id="lbnkVidTtile1" runat="Server" OnClientClick="return PostToNewWindow();" />My Facebook
narasappa
Participant
960 Points
458 Posts
Re: opening page in New Window
Apr 30, 2012 12:38 PM|LINK
hi
thanks .. but my link buttons r within gridview .. im binding my GV on run time pls go through my code..
ravi.jadiyannavar@gmail.com
Pls Mark This Post As Answer If it Helps U..
Thanku
Eng-Mondy
Member
189 Points
71 Posts
Re: opening page in New Window
Apr 30, 2012 12:41 PM|LINK
u welcome friend .. yeah i know that ur Linkbutton inside a Gridview ... that also works .. go to ASPX Page and Put the Script and Call it at ur Gridview's linkbutton event "onclientclick " as i explaned above
.
My Facebook
nageshrgosul
Participant
1044 Points
424 Posts
Re: opening page in New Window
Apr 30, 2012 12:58 PM|LINK
Hi, Go through with this... hope u may solve
<script type="text/javascript"> function PostToNewWindow() { originalTarget = document.forms[0].target; document.forms[0].target='_blank'; window.setTimeout("document.forms[0].target=originalTarget;",300); return true; } </script> <asp:LinkButton id="lbnkVidTtile1" runat="Server" OnClientClick="return PostToNewWindow();" />Eng-Mondy
Member
189 Points
71 Posts
Re: opening page in New Window
Apr 30, 2012 01:10 PM|LINK
i did it for u .. and here the <Body> tag .. with full code ...
<body> <script type="text/javascript"> function PostToNewWindow() { originalTarget = document.forms[0].target; document.forms[0].target = '_blank'; window.setTimeout("document.forms[0].target=originalTarget;", 300); return true; } </script> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="181px"> <Columns> <asp:BoundField DataField="user_name" HeaderText="user_name" SortExpression="user_name" Visible="False" /> <asp:BoundField DataField="arts" HeaderText="arts" SortExpression="arts" /> <asp:BoundField DataField="egypt" HeaderText="egypt" SortExpression="egypt" /> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Bind("user_name") %>' OnClientClick="return PostToNewWindow();"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings: Choose You Connection String %>" SelectCommand="SELECT [user_name], [arts], [egypt] FROM [admins]"></asp:SqlDataSource> </div> </form> </body>My Facebook
AidyF
Star
9184 Points
1570 Posts
Re: opening page in New Window
Apr 30, 2012 01:53 PM|LINK
The reason you might not think the posted solution will work is because link buttons are "smoke and mirrors". It's not a "normal" link. When your page is rendered, the link simply calls javascript when clicked, and that javascript submits the form. Making the form submit to a new window will solve your issue. However you might have a problem if other controls on the page also submit (buttons etc) but you don't want those to open in a new window.