I have a link button inside repeater and i just want to open it in a new tab with session. I have tried many things but it doesn't work well.
<asp:Repeater runat="server" ID="RP_UniversityInfo">
<ItemTemplate>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="boxes">
<div class="boxes_img ImageWrapper">
<asp:LinkButton runat="server" ID="Link_Uni_Image"
CommandName="Link_Uni_Image"
CommandArgument='<%#Eval("id") %>'
OnClick="Link_Uni_Image_Click">
<img class="img-responsive"
src='<%# "upload/"+ Eval("image") %>' alt='<%#Eval("name") %>'>
<div class="PStyleNe"></div>
</asp:LinkButton>
<div class="box_type"><%#Eval("con_name") %></div>
</div>
<h2 class="title">
<asp:LinkButton runat="server" ID="Link_Uni"
CommandName="Link_Uni"
CommandArgument='<%#Eval("id") %>'
OnClick="Link_Uni_Click">
<%#Eval("name") %>
</asp:LinkButton>
</h2>
</div><!-- end boxes -->
</div>
</ItemTemplate>
</asp:Repeater>
LinkButton LnkBtn = (LinkButton)sender;
RepeaterItem item = LnkBtn.NamingContainer as RepeaterItem;
University_Id = Convert.ToInt32(LnkBtn.CommandArgument);
Session["university"] = University_Id;
Response.Redirect("University_Details.aspx");
I tried JavaScript also but same result. It opens a new tab but refreshes whole page and also opens new tab by clicking on Dropdownlist also. Help me out!
I suggest you to use <asp:HyperLink>
that will open link in new tab.
<asp:HyperLink NavigateUrl="http://websiteurl.com" Target="_blank" />
Because the
LinkButton
control is used to create a hyperlink-style button on the Web page. TheLinkButton
control has the same appearance as aHyperLink
control, but has the same functionality as a Button control. If you want to link to another Web page when the control is clicked, consider using theHyperLink
control.
Edit : If you can not change to HyperLink then follow below approach.
Add OnClientClick event.
OnClientClick="aspnetForm.target ='_blank';"
So on click it will call JavaScript
function and it will open respective link in new tab.
<asp:LinkButton id="lnkLink" OnClientClick="aspnetForm.target ='_blank';" runat="Server" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.